dateutil icon indicating copy to clipboard operation
dateutil copied to clipboard

utcfromtimestamp deprecated

Open DanielJOHara opened this issue 1 year ago • 3 comments

My project generated a deprecated function warning for utcfromtimestamp.

EPOCH = datetime.datetime.utcfromtimestamp(0)

This blog suggest a replacement https://blog.ganssle.io/articles/2019/11/utcnow.html EPOCH = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc)

DanielJOHara avatar Feb 13 '24 16:02 DanielJOHara

Same here. My stack has three libraries that depend on dateutil. A minor release addressing this would be very welcome

bwalsh avatar Feb 15 '24 14:02 bwalsh

See #1314

troyswanson avatar Feb 15 '24 20:02 troyswanson

The original code using utcfromtimestamp gives a naive datetime; the "correct" way to get this without triggering the deprecation warning would be

EPOCH = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc).replace(tzinfo=None)

I'm neither familiar with dateutil's codebase nor do I think this is elegant - but, if you know what you're doing, it is OK I think.

FObersteiner avatar Feb 16 '24 12:02 FObersteiner

It looks like this was fixed in #1285, but the last release of this package was in 2021. There have been a bunch of PRs merged since then, I wonder if there is a plan to do another release at some point to get those fixes out the door?

rosteen avatar Feb 29 '24 16:02 rosteen

@rosteen see https://github.com/dateutil/dateutil/pull/1130#issuecomment-1808635487

edgarrmondragon avatar Feb 29 '24 16:02 edgarrmondragon

@rosteen see #1130 (comment)

Thanks, I dug in and saw all the discussion of that after I commented (I missed that the comment above was linking to release discussion).

rosteen avatar Feb 29 '24 16:02 rosteen