Skip to content

Commit

Permalink
Fix LocalSystemDateTime not setting the correct offset (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
ariebovenberg committed Apr 2, 2024
1 parent 8e0e06d commit 3bc5cc0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "whenever"
version = "0.5.0"
version = "0.5.1"
description = "Sensible and typesafe datetimes"
authors = ["Arie Bovenberg <[email protected]>"]
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions src/whenever/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# - It saves some overhead
from __future__ import annotations

__version__ = "0.5.0"
__version__ = "0.5.1"

import re
import sys
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion tests/test_local_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit 3bc5cc0

Please sign in to comment.