|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +from datetime import datetime |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from dateutil import tz |
| 8 | + |
3 | 9 | import pendulum |
4 | 10 |
|
5 | 11 | from tests.conftest import assert_datetime |
@@ -36,3 +42,22 @@ def test_astimezone(): |
36 | 42 | d = d.astimezone(pendulum.timezone("Europe/Paris")) |
37 | 43 | assert d.timezone_name == "Europe/Paris" |
38 | 44 | assert_datetime(d, now.year, now.month, now.day, now.hour + 1, now.minute) |
| 45 | + |
| 46 | + |
| 47 | +def test_astimezone_with_tzinfo_doing_arithmetic_in_fromutc(): |
| 48 | + # dateutil's tzoffset.fromutc() adds its offset to the datetime it's given |
| 49 | + cest = tz.tzoffset("CEST", 7200) |
| 50 | + d = pendulum.datetime(2024, 7, 1, 12) |
| 51 | + |
| 52 | + d = d.astimezone(cest) |
| 53 | + assert isinstance(d, pendulum.DateTime) |
| 54 | + assert d.tzinfo is cest |
| 55 | + assert_datetime(d, 2024, 7, 1, 14) |
| 56 | + |
| 57 | + |
| 58 | +@pytest.mark.parametrize("fold, hour", [(0, 0), (1, 1)]) |
| 59 | +def test_astimezone_respects_fold(fold, hour): |
| 60 | + d = pendulum.datetime(2024, 10, 27, 2, 30, tz="Europe/Paris", fold=fold) |
| 61 | + |
| 62 | + d = d.astimezone(pendulum.UTC) |
| 63 | + assert d == datetime(2024, 10, 27, hour, 30, tzinfo=pendulum.UTC) |
0 commit comments