Skip to content
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
fix(summary): set all datetimes explicitly to UTC
  • Loading branch information
Angeluz-07 committed May 12, 2020
commit 1802f4e0c17d2855e55d198562b93a861779cabe
7 changes: 4 additions & 3 deletions commons/data_access_layer/cosmos_db.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataclasses
import logging
import uuid
from datetime import datetime
from datetime import datetime, timezone
from typing import Callable, List, Dict

import azure.cosmos.cosmos_client as cosmos_client
Expand Down Expand Up @@ -385,7 +385,7 @@ def init_app(app: Flask) -> None:


def current_datetime() -> datetime:
return datetime.utcnow()
return datetime.now(timezone.utc)


def datetime_str(value: datetime) -> str:
Expand Down Expand Up @@ -418,7 +418,7 @@ def get_current_month() -> int:

def get_date_range_of_month(year: int, month: int) -> Dict[str, str]:
first_day_of_month = 1
start_date = datetime(year=year, month=month, day=first_day_of_month)
start_date = datetime(year=year, month=month, day=first_day_of_month,tzinfo=timezone.utc)

last_day_of_month = get_last_day_of_month(year=year, month=month)
end_date = datetime(
Expand All @@ -429,6 +429,7 @@ def get_date_range_of_month(year: int, month: int) -> Dict[str, str]:
minute=59,
second=59,
microsecond=999999,
tzinfo=timezone.utc
)

return {
Expand Down
11 changes: 7 additions & 4 deletions time_tracker_api/time_entries/custom_modules/worked_time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from commons.data_access_layer.cosmos_db import (
current_datetime,
current_datetime_str,
Expand All @@ -9,7 +9,7 @@


def start_datetime_of_current_month() -> datetime:
return datetime(year=get_current_year(), month=get_current_month(), day=1,)
return datetime(year=get_current_year(), month=get_current_month(), day=1, tzinfo=timezone.utc)


def start_datetime_of_current_week() -> datetime:
Expand All @@ -30,9 +30,12 @@ def start_datetime_of_current_month_str() -> str:


def str_to_datetime(
value: str, conversion_format: str = '%Y-%m-%dT%H:%M:%S.%f'
value: str, conversion_format: str = '%Y-%m-%dT%H:%M:%S.%fZ'
) -> datetime:
return datetime.strptime(value, conversion_format)
if 'Z' in value:
return datetime.strptime(value, conversion_format).astimezone(timezone.utc)
else:
return datetime.fromisoformat(value).astimezone(timezone.utc)


def date_range():
Expand Down