Skip to content

Commit e9e3f25

Browse files
yarikopticclaude
andauthored
Fix time-of-day-dependent failure in series_time validation (#395)
The series_time > content_time check was performed regardless of whether series_date and content_date differed. When content_time defaults to now.time(), this caused spurious failures depending on what time of day the code (or tests) ran. The time comparison is now only performed when the dates are equal. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 22b0b79 commit e9e3f25

2 files changed

Lines changed: 57 additions & 6 deletions

File tree

src/highdicom/base.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,15 @@ def __init__(
293293
"'series_time' may not be specified without "
294294
"'series_date'."
295295
)
296-
if content_time is not None:
297-
if series_time > content_time:
298-
raise ValueError(
299-
"'series_time' must not be later than content time."
300-
)
296+
if (
297+
content_time is not None and
298+
content_date is not None and
299+
series_date == content_date and
300+
series_time > content_time
301+
):
302+
raise ValueError(
303+
"'series_time' must not be later than content time."
304+
)
301305
self.SeriesTime = series_time
302306

303307
if content_qualification is not None:

tests/test_base.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,59 @@ def test_series_datetime(self):
9999
manufacturer_model_name='foo-bar',
100100
software_versions='v1.0.0',
101101
transfer_syntax_uid=ExplicitVRLittleEndian,
102-
series_date=datetime.date(2000, 12, 1),
102+
content_date=datetime.date(2024, 6, 15),
103+
content_time=datetime.time(14, 0, 0),
104+
series_date=datetime.date(2024, 6, 15),
103105
series_time=datetime.time(12, 34, 56),
104106
)
105107
assert hasattr(instance, 'SeriesDate')
106108
assert hasattr(instance, 'SeriesTime')
107109

110+
def test_series_datetime_earlier_date(self):
111+
# series_time > content_time is fine when series_date < content_date
112+
instance = SOPClass(
113+
study_instance_uid=UID(),
114+
series_instance_uid=UID(),
115+
series_number=1,
116+
sop_instance_uid=UID(),
117+
sop_class_uid='1.2.840.10008.5.1.4.1.1.88.33',
118+
instance_number=1,
119+
modality='SR',
120+
manufacturer='highdicom',
121+
manufacturer_model_name='foo-bar',
122+
software_versions='v1.0.0',
123+
transfer_syntax_uid=ExplicitVRLittleEndian,
124+
content_date=datetime.date(2024, 6, 15),
125+
content_time=datetime.time(8, 0, 0),
126+
series_date=datetime.date(2024, 6, 14),
127+
series_time=datetime.time(23, 59, 59),
128+
)
129+
assert hasattr(instance, 'SeriesDate')
130+
assert hasattr(instance, 'SeriesTime')
131+
132+
def test_series_time_after_content_same_date(self):
133+
msg = (
134+
"'series_time' must not be later than content time."
135+
)
136+
with pytest.raises(ValueError, match=msg):
137+
SOPClass(
138+
study_instance_uid=UID(),
139+
series_instance_uid=UID(),
140+
series_number=1,
141+
sop_instance_uid=UID(),
142+
sop_class_uid='1.2.840.10008.5.1.4.1.1.88.33',
143+
instance_number=1,
144+
modality='SR',
145+
manufacturer='highdicom',
146+
manufacturer_model_name='foo-bar',
147+
software_versions='v1.0.0',
148+
transfer_syntax_uid=ExplicitVRLittleEndian,
149+
content_date=datetime.date(2024, 6, 15),
150+
content_time=datetime.time(8, 0, 0),
151+
series_date=datetime.date(2024, 6, 15),
152+
series_time=datetime.time(12, 34, 56),
153+
)
154+
108155
def test_series_date_without_time(self):
109156
msg = (
110157
"'series_time' may not be specified without "

0 commit comments

Comments
 (0)