Skip to content

Commit 50889cc

Browse files
Add case for timestamps with timezone offset
1 parent 7c11bdb commit 50889cc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

isyntax2raw/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,17 @@ def acquisition_datetime(self):
327327
timestamp = str(pe_in.DICOM_ACQUISITION_DATETIME).strip()
328328
else:
329329
timestamp = pe_in.acquisition_datetime.strip()
330-
# older files store the date time in YYYYmmddHHMMSS.ffffff format
330+
# older files store the date time in YYYYmmddHHMMSS.ffffff format,
331+
# optionally with a timezone offset appended
331332
# newer files use ISO 8601, i.e. YYYY-mm-ddTHH:mm:ss
332333
# other timestamp formats may be used in the future
333334
try:
334-
# Handle "special" isyntax date/time format
335-
return datetime.strptime(timestamp, "%Y%m%d%H%M%S.%f")
335+
try:
336+
# Handle "special" isyntax date/time format
337+
return datetime.strptime(timestamp, "%Y%m%d%H%M%S.%f")
338+
except ValueError:
339+
# Handle "special" isyntax date/time format with timezone
340+
return datetime.strptime(timestamp, "%Y%m%d%H%M%S.%f%z")
336341
except ValueError:
337342
# Handle other date/time formats (such as ISO 8601)
338343
return parse(timestamp)

0 commit comments

Comments
 (0)