Skip to content

Commit

Permalink
Merge pull request #900 from sirosen/fix-timers-tz-handling
Browse files Browse the repository at this point in the history
Preserve tzinfo if it is set in Timer payloads
  • Loading branch information
sirosen authored Nov 3, 2023
2 parents c6e8afb + e0d8125 commit 2446c7c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed
~~~~~

- When serializing ``TransferTimer`` data, do not convert to UTC if the input
was a valid datetime with an offset. (:pr:`NUMBER`)
4 changes: 3 additions & 1 deletion src/globus_sdk/services/timer/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ def from_transfer_data(

def _format_date(date: str | dt.datetime | MissingType) -> str | MissingType:
if isinstance(date, dt.datetime):
return date.astimezone(dt.timezone.utc).replace(microsecond=0).isoformat()
if date.tzinfo is None:
date = date.astimezone(dt.timezone.utc)
return date.isoformat(timespec="seconds")
else:
return date
7 changes: 6 additions & 1 deletion tests/unit/helpers/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ def test_transfer_timer_removes_disallowed_fields():
# even though this string is "obviously" not a valid datetime, we don't
# translate it when we create the schedule
("tomorrow", "tomorrow"),
# use a fixed (known) timestamp and check how it's formatted
# use a fixed (known) timestamp and check how it's formatted as UTC
(datetime.datetime.fromtimestamp(1698385129.7044), "2023-10-27T05:38:49+00:00"),
# use a non-UTC datetime and confirm that it is sent as non-UTC
(
datetime.datetime.fromisoformat("2023-10-27T05:38:49.999+01:00"),
"2023-10-27T05:38:49+01:00",
),
),
)
def test_once_timer_schedule_formats_datetime(input_time, expected):
Expand Down

0 comments on commit 2446c7c

Please sign in to comment.