Skip to content

Commit

Permalink
#27: try to strengthen timezone, invane.
Browse files Browse the repository at this point in the history
  • Loading branch information
zgypa committed Apr 30, 2024
1 parent 01a2a32 commit 1e13928
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions dicom4ortho/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def timezone(self) -> datetime.timezone:
"""
try:
return datetime.timezone(datetime.timedelta(hours=int(self._ds.TimezoneOffsetFromUTC)/100))
except ValueError:
except (ValueError, TypeError):
return None

@ timezone.setter
def timezone(self, timezone: datetime.timezone) -> None:
def timezone(self, tz: datetime.timezone) -> None:
''' Set timezone of TimezoneOffsetFromUTC from a Python datetime.timezone object.
If you know the timezone in string format, like "-0900", then you might be better off to set the `_ds` object directly.
Expand All @@ -299,8 +299,15 @@ def timezone(self, timezone: datetime.timezone) -> None:
Returns:
None
'''
self._ds.TimezoneOffsetFromUTC = datetime.datetime.now(
timezone).strftime("%z")
if tz:
offset_seconds = tz.utcoffset(None).total_seconds()
offset_hours = int(offset_seconds // 3600)
offset_minutes = int((offset_seconds % 3600) // 60)
self._ds.TimezoneOffsetFromUTC = f"{offset_hours:+03.0f}{offset_minutes:02d}"
else:
self._ds.TimezoneOffsetFromUTC = None



@ property
def acquisition_datetime(self):
Expand Down

0 comments on commit 1e13928

Please sign in to comment.