Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/dve/metadata_parser/domain_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ def validate(cls, value: Union[dt.time, dt.datetime, str]) -> dt.time | None:
raise ValueError("Provided time has timezone, but this is forbidden for this field")
if cls.TIMEZONE_TREATMENT == "require" and not new_time.tzinfo:
raise ValueError("Provided time missing timezone, but this is required for this field")

if isinstance(value, str) and cls.TIME_FORMAT and value != str(new_time):
raise ValueError("Provided time is not matching expected time format supplied.")
return new_time

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions tests/test_model_generation/test_domain_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,6 @@ def test_reportingperiod_raises(field, value):
["23:00:00Z", None, "require", dt.time(23, 0, 0, tzinfo=UTC)],
["12:00:00Zam", None, "permit", dt.time(0, 0, 0, tzinfo=UTC)],
["12:00:00pm", None, "forbid", dt.time(12, 0, 0)],
["1970-01-01", "%Y-%m-%d", "forbid", dt.time(0, 0)],
# not great that it effectively returns incorrect time object here. However, this would be
# down to user error in setting up the dischema.
[dt.datetime(2025, 12, 1, 13, 0, 5), "%H:%M:%S", "forbid", dt.time(13, 0, 5)],
[dt.datetime(2025, 12, 1, 13, 0, 5, tzinfo=UTC), "%H:%M:%S", "require", dt.time(13, 0, 5, tzinfo=UTC)],
[dt.time(13, 0, 0), "%H:%M:%S", "forbid", dt.time(13, 0, 0)],
Expand All @@ -364,6 +361,9 @@ def test_formattedtime(
["23:00:00", "%I:%M:%S", "permit",],
["23:00:00", "%H:%M:%S", "require",],
["23:00:00Z", "%I:%M:%S", "forbid",],
["2:10:13", "%H:%M:%S", "forbid",],
["20:0:13", "%H:%M:%S", "forbid",],
["20:10:1", "%H:%M:%S", "forbid",],
[dt.datetime(2025, 12, 1, 13, 0, 5, tzinfo=UTC), "%H:%M:%S", "forbid",],
[dt.time(13, 0, 5, tzinfo=UTC), "%H:%M:%S", "forbid",],
["12:00", "%H:%M:%S", "forbid",],
Expand Down
Loading