Skip to content

Commit c0c0b92

Browse files
committed
Switched to using built-in zoneinfo in favour of pytz
* On python >= 3.9, the builtin package zoneinfo will is used * On python < 3.9, the extra package `backports.zoneinfo` is used
1 parent 5057d0f commit c0c0b92

File tree

3 files changed

+72
-30
lines changed

3 files changed

+72
-30
lines changed

glQiwiApi/utils/date_conversion.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
import sys
21
from datetime import datetime, timezone
32
from typing import Optional
43

54
DEFAULT_QIWI_TIMEZONE = 'Europe/Moscow'
65

7-
if sys.version_info < (3, 9, 0):
8-
try:
9-
import pytz
10-
except ImportError:
11-
raise RuntimeError(
12-
'glQiwiApi requires `pytz` package for python < 3.9'
13-
'as an alternative to a new builtin `zoneinfo`. '
14-
'Please install pytz using pip install pytz.'
15-
)
16-
17-
def to_moscow(obj: datetime) -> datetime:
18-
return obj.astimezone(pytz.timezone(DEFAULT_QIWI_TIMEZONE))
19-
20-
else:
6+
try:
217
import zoneinfo
22-
23-
def to_moscow(obj: datetime) -> datetime:
24-
return obj.astimezone(zoneinfo.ZoneInfo(DEFAULT_QIWI_TIMEZONE))
8+
except ImportError:
9+
import backports.zoneinfo as zoneinfo
2510

2611

2712
def datetime_to_utc_in_iso_format(obj: datetime) -> str:
@@ -37,4 +22,4 @@ def datetime_to_iso8601_with_moscow_timezone(obj: Optional[datetime]) -> str:
3722
"""
3823
if not isinstance(obj, datetime):
3924
return '' # pragma: no cover
40-
return to_moscow(obj).isoformat(timespec='seconds')
25+
return obj.astimezone(zoneinfo.ZoneInfo(DEFAULT_QIWI_TIMEZONE)).isoformat(timespec='seconds')

poetry.lock

Lines changed: 67 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ classifiers = [
4343

4444
[tool.poetry.dependencies]
4545
python = "^3.7"
46-
pytz = { version = "2022.6", python = "<3.9"}
46+
"backports.zoneinfo" = { version = "^0.2.1", extras = ["tzdata"], python = "<3.9"}
4747
aiohttp = "^3.8.3"
4848
pydantic = "^1.10.2"
4949
typing_extensions = { version = "^4.0.1", python = "<=3.7" }

0 commit comments

Comments
 (0)