diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1774d37b..ce36889a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ 🚀 Changelog ============ +0.5.1 (2024-04-02) +------------------ + +- Fix ``LocalSystemDateTime.now()`` not setting the correct offset (#104) + 0.5.0 (2024-03-21) ------------------ diff --git a/pyproject.toml b/pyproject.toml index c68cb6e5..d252a819 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "whenever" -version = "0.5.0" +version = "0.5.1" description = "Sensible and typesafe datetimes" authors = ["Arie Bovenberg "] license = "MIT" diff --git a/src/whenever/__init__.py b/src/whenever/__init__.py index 6e142303..931c6485 100644 --- a/src/whenever/__init__.py +++ b/src/whenever/__init__.py @@ -32,7 +32,7 @@ # - It saves some overhead from __future__ import annotations -__version__ = "0.5.0" +__version__ = "0.5.1" import re import sys @@ -3492,7 +3492,7 @@ def __init__( @classmethod def now(cls) -> LocalSystemDateTime: """Create an instance from the current time""" - return cls._from_py_unchecked(_datetime.now()) + return cls._from_py_unchecked(_datetime.now().astimezone(None)) def canonical_format(self, sep: Literal[" ", "T"] = "T") -> str: return self._py_dt.isoformat(sep) diff --git a/tests/test_local_datetime.py b/tests/test_local_datetime.py index aa9645b4..a17a8a15 100644 --- a/tests/test_local_datetime.py +++ b/tests/test_local_datetime.py @@ -617,6 +617,8 @@ def test_from_timestamp(): with pytest.raises((OSError, OverflowError)): LocalSystemDateTime.from_timestamp(1_000_000_000_000_000_000) + assert LocalSystemDateTime.from_timestamp(0).offset == hours(-5) + @local_nyc_tz() def test_repr(): @@ -660,7 +662,8 @@ def test_wrong_tzinfo(self): @local_nyc_tz() def test_now(): now = LocalSystemDateTime.now() - py_now = py_datetime.now(ZoneInfo("America/New_York")).replace(tzinfo=None) + assert now.offset == hours(-4) + py_now = py_datetime.now(ZoneInfo("America/New_York")) assert py_now - now.py_datetime() < timedelta(seconds=1)