Skip to content

Commit

Permalink
Fix dt warnings with timezones
Browse files Browse the repository at this point in the history
  • Loading branch information
natikgadzhi committed Jun 1, 2024
1 parent 3e3fec6 commit 77ec3ae
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def from_timestamp(timestamp: int | float, tz: str | Timezone = UTC) -> DateTime
"""
Create a DateTime instance from a timestamp.
"""
dt = _datetime.datetime.utcfromtimestamp(timestamp)
dt = _datetime.datetime.fromtimestamp(timestamp, tz=_datetime.UTC)

dt = datetime(
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond
Expand Down
2 changes: 1 addition & 1 deletion src/pendulum/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ def fromtimestamp(cls, t: float, tz: datetime.tzinfo | None = None) -> Self:

@classmethod
def utcfromtimestamp(cls, t: float) -> Self:
return cls.instance(datetime.datetime.utcfromtimestamp(t), tz=None)
return cls.instance(datetime.datetime.fromtimestamp(t, datetime.UTC), tz=None)

@classmethod
def fromordinal(cls, n: int) -> Self:
Expand Down
2 changes: 1 addition & 1 deletion tests/datetime/test_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_fromtimestamp():

def test_utcfromtimestamp():
p = pendulum.DateTime.utcfromtimestamp(0)
dt = datetime.utcfromtimestamp(0)
dt = datetime.fromtimestamp(0, pendulum.UTC)

assert p == dt

Expand Down

0 comments on commit 77ec3ae

Please sign in to comment.