Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid usage of deprecated datetime.datetime.utcfromtimestamp in pendulum.from_timestamp #803

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/pendulum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +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(
dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond
)
dt = DateTime.fromtimestamp(timestamp, tz=UTC)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current suggestion is recursive and does not use the correct keyword:

Suggested change
dt = DateTime.fromtimestamp(timestamp, tz=UTC)
dt = _datetime.datetime.fromtimestamp(timestamp, tzinfo=UTC)

For the develop branch, the change must be done in pendulum/pendulum.py:491

dt = datetime.datetime.utcfromtimestamp(timestamp).replace(tzinfo=UTC)

to

dt = datetime.datetime.fromtimestamp(timestamp, tzinfo=UTC)


if tz is not UTC or tz != "UTC":
dt = dt.in_timezone(tz)
Expand Down
Loading