|
| 1 | +from datetime import datetime, timedelta |
| 2 | +from zoneinfo import ZoneInfo |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from eones.core.date import Date |
| 7 | +from eones.core.delta import Delta |
| 8 | + |
| 9 | + |
| 10 | +def test_leap_year_add_and_subtract(): |
| 11 | + base = Date(datetime(2020, 2, 29, tzinfo=ZoneInfo("UTC"))) |
| 12 | + plus_one = base + Delta(years=1) |
| 13 | + assert plus_one.to_datetime() == datetime(2021, 2, 28, tzinfo=ZoneInfo("UTC")) |
| 14 | + minus_one = plus_one - Delta(years=1) |
| 15 | + assert minus_one.to_datetime() == datetime(2020, 2, 28, tzinfo=ZoneInfo("UTC")) |
| 16 | + plus_four = base + Delta(years=4) |
| 17 | + assert plus_four.to_datetime() == datetime(2024, 2, 29, tzinfo=ZoneInfo("UTC")) |
| 18 | + |
| 19 | + |
| 20 | +def test_dst_spring_forward_hour_skipped(): |
| 21 | + zone = "America/New_York" |
| 22 | + dt = Date(datetime(2023, 3, 12, 1, 30, tzinfo=ZoneInfo(zone)), tz=zone) |
| 23 | + shifted = dt + timedelta(hours=1) |
| 24 | + result = shifted.to_datetime() |
| 25 | + assert result.hour == 2 |
| 26 | + assert result.utcoffset().total_seconds() / 3600 == -5 |
| 27 | + |
| 28 | + |
| 29 | +def test_add_then_subtract_symmetry(): |
| 30 | + base = Date(datetime(2024, 5, 15, 10, 0, tzinfo=ZoneInfo("UTC"))) |
| 31 | + delta = Delta(days=3, hours=5) |
| 32 | + result = (base + delta) - delta |
| 33 | + assert result == base |
0 commit comments