From a5669fc8445c0381a8705fa2aee0090a2c62b309 Mon Sep 17 00:00:00 2001 From: Peter Nilsson Date: Tue, 16 Jan 2024 10:58:54 +0100 Subject: [PATCH 1/4] add fold to constructor --- src/heliclockter/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/heliclockter/__init__.py b/src/heliclockter/__init__.py index a64f424..5f6246b 100644 --- a/src/heliclockter/__init__.py +++ b/src/heliclockter/__init__.py @@ -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, ) From e21a91045c4cb12fb7b08a071696661a0fd69f04 Mon Sep 17 00:00:00 2001 From: Peter Nilsson Date: Tue, 16 Jan 2024 11:14:35 +0100 Subject: [PATCH 2/4] add tests for fold --- tests/instantiation_test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/instantiation_test.py b/tests/instantiation_test.py index fed67b1..927f8ea 100644 --- a/tests/instantiation_test.py +++ b/tests/instantiation_test.py @@ -272,3 +272,10 @@ 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(fold: int) -> None: + dt = datetime_tz(2023, 10, 29, 2, 30, fold=fold, tzinfo=ZoneInfo("Europe/Berlin")) + iso_offset = "+01:00" if fold == 1 else '+02:00' + assert dt.isoformat().endswith(iso_offset) From 9b12f7509ae9f024313085e249df270c75b05ea7 Mon Sep 17 00:00:00 2001 From: Peter Nilsson Date: Tue, 16 Jan 2024 12:01:40 +0100 Subject: [PATCH 3/4] add tests for utc fold --- tests/instantiation_test.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/instantiation_test.py b/tests/instantiation_test.py index 927f8ea..ac442e7 100644 --- a/tests/instantiation_test.py +++ b/tests/instantiation_test.py @@ -275,7 +275,13 @@ def test_future_and_past_no_tz() -> None: @parameterized.expand([(0,), (1,)]) -def test_fold(fold: int) -> None: +def test_fold_tz(fold: int) -> None: dt = datetime_tz(2023, 10, 29, 2, 30, fold=fold, tzinfo=ZoneInfo("Europe/Berlin")) - iso_offset = "+01:00" if fold == 1 else '+02:00' - assert dt.isoformat().endswith(iso_offset) + 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" From 9f387c0ac181ebe65ec14b72972fa2a8bf1f769c Mon Sep 17 00:00:00 2001 From: Peter Nilsson Date: Mon, 5 Feb 2024 13:22:39 +0100 Subject: [PATCH 4/4] 1.3.0 add changelog and change version --- CHANGELOG.md | 3 ++- src/heliclockter/__init__.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 5f6246b..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')