Skip to content

Commit

Permalink
feat(Voice): timestamp validation added
Browse files Browse the repository at this point in the history
  • Loading branch information
650elx committed May 10, 2024
1 parent 9def0cc commit b41187d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sinch/core/deserializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@


def timestamp_to_datetime_in_utc_deserializer(timestamp: str):
"""
Older Python versions (like 3.9) do not support "Z" as a TZ information.
One needs to use '+00:00' to represent UTC tz.
"""
if timestamp.endswith("Z"):
timestamp = timestamp[:-1]

return datetime.fromisoformat(timestamp + "+00:00")
6 changes: 6 additions & 0 deletions tests/unit/test_serdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ def test_timestamp_to_datetime_in_utc_deserializer():
datetime_in_utc = timestamp_to_datetime_in_utc_deserializer("2024-02-15T13:01:29")
assert isinstance(datetime_in_utc, datetime.datetime)
assert datetime_in_utc.tzinfo == datetime.timezone.utc


def test_timestamp_to_datetime_in_utc_deserializer_with_added_tz():
datetime_in_utc = timestamp_to_datetime_in_utc_deserializer("2024-02-15T13:01:29Z")
assert isinstance(datetime_in_utc, datetime.datetime)
assert datetime_in_utc.tzinfo == datetime.timezone.utc

0 comments on commit b41187d

Please sign in to comment.