Skip to content

Commit

Permalink
Use local tzinfo at test
Browse files Browse the repository at this point in the history
Refs: #37
  • Loading branch information
atuonufure committed Feb 6, 2024
1 parent a50dc56 commit 00906fa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 0 additions & 6 deletions fhirpathpy/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,6 @@ def _getDateTimeInt(self):
def _extractDateByPrecision(self, date_obj: datetime, precision):
if date_obj.tzinfo is None or date_obj.tzinfo.utcoffset(date_obj) is None:
date_obj = date_obj.replace(tzinfo=tz.tzutc())

format = {
1: "%Y",
2: "%Y-%m",
Expand All @@ -773,17 +772,12 @@ def _extractDateByPrecision(self, date_obj: datetime, precision):
6: "%Y-%m-%dT%H:%M:%S",
7: "%Y-%m-%dT%H:%M:%S",
}

formatted_date = date_obj.strftime(format.get(precision, ""))

if precision == 7:
milliseconds = date_obj.strftime("%f")[:3]

tz_offset = date_obj.strftime("%z")
tz_formatted = tz_offset[:3] + ":" + tz_offset[3:]

formatted_date = f"{formatted_date}.{milliseconds}{tz_formatted}"

return formatted_date

def _convertDatetime(self, date_list):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_additional.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


def datetime_tostring_tzinfo_test():
tz_offset = datetime.timezone(datetime.timedelta(hours=2))
local_tz = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo
# tz_offset = datetime.timezone(datetime.timedelta(hours=2))
with freeze_time(
lambda: datetime.datetime(
year=2020,
Expand All @@ -14,7 +15,7 @@ def datetime_tostring_tzinfo_test():
minute=52,
second=15,
microsecond=123456,
tzinfo=tz_offset,
tzinfo=local_tz,
)
):
assert evaluate({}, "(now() + 1 month).toString()")[0] == "2020-09-20T13:52:15.123+00:00"

0 comments on commit 00906fa

Please sign in to comment.