Skip to content

Commit 58b4835

Browse files
committed
Revert "feat: remove python-dateutil dependency (#221)"
This reverts commit 8ea4aa0.
1 parent 4be240c commit 58b4835

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

hcloud/_compat.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import sys
12
from datetime import datetime
23

4+
if sys.version_info < (3, 11):
5+
from dateutil.parser import isoparse as baseisoparse
36

4-
def isoparse(value: str) -> datetime:
5-
# Python <3.11 doesn't fully support parsing ISO8601 datetime strings. This
6-
# workaround replaces the ending `Z` or `z` with `+00:00` and allows
7-
# `datetime.fromisoformat` to parse the datetime string.
8-
if value[-1] in "Zz":
9-
value = value[:-1] + "+00:00"
107

11-
return datetime.fromisoformat(value)
8+
def isoparse(value: str) -> datetime:
9+
if sys.version_info < (3, 11):
10+
return baseisoparse(value)
11+
else:
12+
return datetime.fromisoformat(value)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
],
3838
python_requires=">=3.7",
3939
install_requires=[
40+
"python-dateutil>=2.7.5;python_version<'3.11'",
4041
"requests>=2.20",
4142
],
4243
extras_require={

tests/unit/test_compat.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,19 @@
2323
),
2424
),
2525
(
26-
"2023-06-29T15:37:22Z",
27-
datetime(2023, 6, 29, 15, 37, 22, tzinfo=timezone.utc),
26+
"2023-06-29T15:37:22.123+00:00",
27+
datetime(2023, 6, 29, 15, 37, 22, 123000, tzinfo=timezone.utc),
28+
),
29+
(
30+
"2023-06-29T15:37:22.1234+00:00",
31+
datetime(2023, 6, 29, 15, 37, 22, 123400, tzinfo=timezone.utc),
2832
),
2933
(
30-
"2023-06-29T15:37:22z",
34+
"2023-06-29T15:37:22.123456+00:00",
35+
datetime(2023, 6, 29, 15, 37, 22, 123456, tzinfo=timezone.utc),
36+
),
37+
(
38+
"2023-06-29T15:37:22Z",
3139
datetime(2023, 6, 29, 15, 37, 22, tzinfo=timezone.utc),
3240
),
3341
],

0 commit comments

Comments
 (0)