Total Complexity | 3 |
Total Lines | 26 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from datetime import datetime |
||
|
|||
2 | from functools import lru_cache |
||
3 | |||
4 | import pytz |
||
5 | |||
6 | # Date formats |
||
7 | DATE_FORMAT = '%Y-%m-%d' |
||
8 | DATETIME_FORMAT = '%Y-%m-%d %H:%M:%S' |
||
9 | |||
10 | |||
11 | @lru_cache(8192) |
||
12 | def convert_to_utc(dt: datetime, timezone: str) -> datetime: |
||
13 | """Convert naive datetime with timezone label to UTC.""" |
||
14 | |||
15 | zone = pytz.timezone(timezone) |
||
16 | |||
17 | return zone.localize(dt).astimezone(pytz.UTC) |
||
18 | |||
19 | |||
20 | def parse_datetime(d, formatter=DATETIME_FORMAT): |
||
21 | return datetime.strptime(d, formatter) |
||
22 | |||
23 | |||
24 | def parse_date(d): |
||
25 | return parse_datetime(d, formatter=DATE_FORMAT).date() |
||
26 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.