Coverage for filip/utils/datetime.py: 50%
6 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-20 16:54 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-11-20 16:54 +0000
1from datetime import datetime, timezone
4def transform_to_utc_datetime(dt: datetime) -> datetime:
5 """
6 Converts datetime object to utc datetime object with zone
8 Args:
9 dt:
11 Returns:
13 """
14 return dt.astimezone(tz=timezone.utc)
17def convert_datetime_to_iso_8601_with_z_suffix(dt: datetime) -> str:
18 """
19 Converts datetime object to iso8601 notation with z-suffix
21 Args:
22 dt: datetime object
24 Returns:
25 String in iso 8601 notation with z-suffix
26 """
27 dt = transform_to_utc_datetime(dt)
28 return dt.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3]+'Z'