Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source Dixa: fix timezone #4696

Merged
merged 1 commit into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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