Skip to content

Commit 7c11bdb

Browse files
authored
Merge pull request #39 from melissalinkert/timestamp-format
Attempt to handle ISO 8601 dates
2 parents f59ef62 + 3b70e2d commit 7c11bdb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

isyntax2raw/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import softwarerenderbackend
2020
import zarr
2121

22+
from dateutil.parser import parse
23+
2224
from datetime import datetime
2325
from concurrent.futures import ALL_COMPLETED, ThreadPoolExecutor, wait
2426
from threading import BoundedSemaphore
@@ -322,10 +324,18 @@ def get_image_metadata_sdk_v2(self, image_no):
322324
def acquisition_datetime(self):
323325
pe_in = self.pixel_engine["in"]
324326
if self.sdk_v1:
325-
timestamp = str(pe_in.DICOM_ACQUISITION_DATETIME)
327+
timestamp = str(pe_in.DICOM_ACQUISITION_DATETIME).strip()
326328
else:
327-
timestamp = pe_in.acquisition_datetime
328-
return datetime.strptime(timestamp, "%Y%m%d%H%M%S.%f")
329+
timestamp = pe_in.acquisition_datetime.strip()
330+
# older files store the date time in YYYYmmddHHMMSS.ffffff format
331+
# newer files use ISO 8601, i.e. YYYY-mm-ddTHH:mm:ss
332+
# other timestamp formats may be used in the future
333+
try:
334+
# Handle "special" isyntax date/time format
335+
return datetime.strptime(timestamp, "%Y%m%d%H%M%S.%f")
336+
except ValueError:
337+
# Handle other date/time formats (such as ISO 8601)
338+
return parse(timestamp)
329339

330340
def barcode(self):
331341
pe_in = self.pixel_engine["in"]

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def read(fname):
8686
'zarr==2.8.1',
8787
'kajiki==0.8.2',
8888
'fsspec>=0.9.0',
89+
'python-dateutil>=2.8.2'
8990
],
9091
tests_require=[
9192
'flake8',

0 commit comments

Comments
 (0)