diff --git a/CHANGELOG.md b/CHANGELOG.md index e519478..12b5ce7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ 1.3.0 ----- -Released 2024-01-08. +Released 2024-02-05. **Breaking changes**: @@ -10,6 +10,7 @@ Released 2024-01-08. Release highlights: - Adds support for python 3.12. +- Adds `fold` to the constructor of `datetime_tz` 1.2.0 ----- diff --git a/src/heliclockter/__init__.py b/src/heliclockter/__init__.py index a64f424..26ce602 100644 --- a/src/heliclockter/__init__.py +++ b/src/heliclockter/__init__.py @@ -44,7 +44,7 @@ tz_local = cast(ZoneInfo, _datetime.datetime.now().astimezone().tzinfo) -__version__ = '1.2.0' +__version__ = '1.3.0' DateTimeTzT = TypeVar('DateTimeTzT', bound='datetime_tz') @@ -77,6 +77,7 @@ def __init__( microsecond: int = 0, *, tzinfo: _datetime.tzinfo, + fold: int = 0, ) -> None: pass @@ -92,6 +93,7 @@ def __init__( # pylint: disable=unused-argument second: int = 0, microsecond: int = 0, tzinfo: _datetime.tzinfo = None, + fold: int = 0, ) -> None: msg = f'{self.__class__} must have a timezone' assert tzinfo is not None and self.tzinfo is not None, msg @@ -167,6 +169,7 @@ def from_datetime(cls: Type[DateTimeTzT], dt: _datetime.datetime) -> DateTimeTzT second=dt.second, microsecond=dt.microsecond, tzinfo=dt.tzinfo, + fold=dt.fold, ).astimezone(tz=assumed_tz) else: @@ -182,6 +185,7 @@ def from_datetime(cls: Type[DateTimeTzT], dt: _datetime.datetime) -> DateTimeTzT second=dt.second, microsecond=dt.microsecond, tzinfo=dt.tzinfo, # type: ignore[arg-type] + fold=dt.fold, ) @classmethod @@ -271,6 +275,7 @@ def __deepcopy__(self: DateTimeTzT, memodict: object) -> DateTimeTzT: second=self.second, microsecond=self.microsecond, tzinfo=self.tzinfo, # type: ignore[arg-type] + fold=self.fold, ) diff --git a/tests/instantiation_test.py b/tests/instantiation_test.py index fed67b1..ac442e7 100644 --- a/tests/instantiation_test.py +++ b/tests/instantiation_test.py @@ -272,3 +272,16 @@ def test_future_and_past_no_tz() -> None: with pytest.raises(DatetimeTzError, match=error_msg): datetime_tz.past(days=2) + + +@parameterized.expand([(0,), (1,)]) +def test_fold_tz(fold: int) -> None: + dt = datetime_tz(2023, 10, 29, 2, 30, fold=fold, tzinfo=ZoneInfo("Europe/Berlin")) + iso = "2023-10-29T02:30:00+01:00" if fold == 1 else '2023-10-29T02:30:00+02:00' + assert dt.isoformat() == iso + + +@parameterized.expand([(0,), (1,)]) +def test_fold_utc(fold: int) -> None: + dt = datetime_utc(2023, 10, 29, 2, 30, fold=fold, tzinfo=ZoneInfo("UTC")) + assert dt.isoformat() == "2023-10-29T02:30:00+00:00"