FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Avoid usage of deprecated `datetime.datetime.utcfromtimestamp` in `pendulum.from_timestamp` by Taragolis · Pull Request #803 · python-pendulum/pendulum · GitHub

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 1 addition & 5 deletions src/pendulum/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Back | FazBrowse Home | New Git URL