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

1from datetime import datetime, timezone 

2 

3 

4def transform_to_utc_datetime(dt: datetime) -> datetime: 

5 """ 

6 Converts datetime object to utc datetime object with zone 

7 

8 Args: 

9 dt: 

10 

11 Returns: 

12 

13 """ 

14 return dt.astimezone(tz=timezone.utc) 

15 

16 

17def convert_datetime_to_iso_8601_with_z_suffix(dt: datetime) -> str: 

18 """ 

19 Converts datetime object to iso8601 notation with z-suffix 

20 

21 Args: 

22 dt: datetime object 

23 

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' 

29 

30