Skip to content

Commit

Permalink
Source Dixa: Pin tz in ConversationExport.ms_timestamp_to_datetime (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermeyer authored Jul 12, 2021
1 parent 4863ea1 commit dbbab8f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


from abc import ABC
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any, Iterable, List, Mapping, MutableMapping, Optional, Tuple

import requests
Expand Down Expand Up @@ -60,7 +60,9 @@ def ms_timestamp_to_datetime(milliseconds: int) -> datetime:
"""
Converts a millisecond-precision timestamp to a datetime object.
"""
return datetime.fromtimestamp(ConversationExport._validate_ms_timestamp(milliseconds) / 1000)
return datetime.fromtimestamp(
ConversationExport._validate_ms_timestamp(milliseconds) / 1000, tz=timezone.utc
)

@staticmethod
def datetime_to_ms_timestamp(dt: datetime) -> int:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,29 @@ def test_validate_ms_timestamp_with_invalid_input_length():

def test_ms_timestamp_to_datetime():
assert ConversationExport.ms_timestamp_to_datetime(1625312980123) == datetime(
year=2021, month=7, day=3, hour=13, minute=49, second=40, microsecond=123000
year=2021,
month=7,
day=3,
hour=11,
minute=49,
second=40,
microsecond=123000,
tzinfo=timezone.utc
)


def test_datetime_to_ms_timestamp():
assert (
ConversationExport.datetime_to_ms_timestamp(datetime(year=2021, month=7, day=3, hour=13, minute=49, second=40, microsecond=123000))
ConversationExport.datetime_to_ms_timestamp(datetime(
year=2021,
month=7,
day=3,
hour=11,
minute=49,
second=40,
microsecond=123000,
tzinfo=timezone.utc)
)
== 1625312980123
)

Expand Down

0 comments on commit dbbab8f

Please sign in to comment.