Skip to content

Commit 352f721

Browse files
committed
whitespace strip dicom datetime values
1 parent 849aa94 commit 352f721

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

heudiconv/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,18 +746,18 @@ def strptime_dcm_da_tm(dcm_data: dcm.Dataset, da_tag: TagType, tm_tag: TagType)
746746
Dicom tag with TM value representation
747747
"""
748748
# https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_6.2.html
749-
date_str = dcm_data[da_tag].value
749+
date_str = dcm_data[da_tag].value.strip()
750750
fmts = ["%Y%m%d",]
751751
date = strptime(date_str, fmts)
752752

753-
time_str = dcm_data[tm_tag].value
753+
time_str = dcm_data[tm_tag].value.strip()
754754
fmts = ["%H", "%H%M", "%H%M%S", "%H%M%S.%f"]
755755
time = strptime(time_str, fmts)
756756

757757
datetime_obj = datetime.datetime.combine(date.date(), time.time())
758758

759759
if utc_offset_dcm := dcm_data.get([0x0008, 0x0201]):
760-
utc_offset = utc_offset_dcm.value
760+
utc_offset = utc_offset_dcm.value.strip()
761761
datetime_obj = datetime_utc_offset(datetime_obj, utc_offset) if utc_offset else datetime_obj
762762
return datetime_obj
763763

@@ -774,13 +774,13 @@ def strptime_dcm_dt(dcm_data: dcm.Dataset, dt_tag: TagType) -> datetime:
774774
Dicom tag with DT value representation
775775
"""
776776
# https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_6.2.html
777-
datetime_str = dcm_data.get(dt_tag)
777+
datetime_str = dcm_data[dt_tag].value.strip()
778778
fmts = ["%Y%z", "%Y%m%z", "%Y%m%d%z", "%Y%m%d%H%z", "%Y%m%d%H%M%z", "%Y%m%d%H%M%S%z", "%Y%m%d%H%M%S.%f%z",
779779
"%Y", "%Y%m", "%Y%m%d", "%Y%m%d%H", "%Y%m%d%H%M", "%Y%m%d%H%M%S", "%Y%m%d%H%M%S.%f"]
780780
datetime_obj = strptime(datetime_str, fmts)
781781

782782
if utc_offset_dcm := dcm_data.get([0x0008, 0x0201]):
783-
if utc_offset := utc_offset_dcm.value:
783+
if utc_offset := utc_offset_dcm.value.strip():
784784
datetime_obj2 = datetime_utc_offset(datetime_obj, utc_offset)
785785
if datetime_obj.tzinfo and datetime_obj2 != datetime_obj:
786786
lgr.warning("Unexpectedly previously parsed datetime %s contains zoneinfo which is different from the one obtained from DICOMs UTFOffset field: %s", datetime_obj, datetime_obj2)

0 commit comments

Comments
 (0)