It's Time For A Change: datetime.utcnow() Is Now Deprecated (blog.miguelgrinberg.com)
from marsokod@lemmy.world to python@programming.dev on 18 Nov 2023 17:18
https://lemmy.world/post/8434829

#python

threaded - newest

AlexWIWA@lemmy.ml on 18 Nov 2023 18:02 collapse

Would have been nice if they had just fixed it instead. Now I have to type more characters

takeda@lemmy.world on 18 Nov 2023 18:52 collapse

Yeah, the names imply that those should be TZ aware. Though I can understand the reasoning, as this change can silently break already broken code that kind of works, and would be a nightmare to fix in a large codebase.

I also disagree with author, about naive datetime. I don’t think there is a good use case for them, and people who use them, do so because they are not aware of the issues.

The only argument I saw was for micro performance improvements, which is kind of funny to care about when programming in python. Since it is implemented in C, the code removing the timezone likely takes more resources.

jim@programming.dev on 18 Nov 2023 19:08 next collapse

While it would be ideal to have all datetime fields in databases and other data stores be time zone aware, that is certainly not the case. Also, SQLite (and probably others) do not have great support for time zones and it’s recommended to store datetimes as UTC (typically unix timestamps).

Deprecating utcnow was a good idea, but they should have replaced it with naive_utcnow. Oh well.

BeardedGingerWonder@feddit.uk on 18 Nov 2023 20:40 collapse

Timezones are a disease and should be eradicated. I will die on this hill.

AlexWIWA@lemmy.ml on 18 Nov 2023 22:19 next collapse

I agree. I hate timezones so much

sugar_in_your_tea@sh.itjust.works on 19 Nov 2023 00:29 collapse

Agreed. I’m an American and wish we could just all be on UTC. Yeah, my workday would start at like 0200, but that’s a sacrifice I’m willing to make.

Sigmatics@lemmy.ca on 19 Nov 2023 13:13 collapse

Everyone on UTC sounds like such a great idea that would solve so many problems.

Unfortunately humans are so dependent on daylight and the day night cycle that it will never work

AlexWIWA@lemmy.ml on 18 Nov 2023 22:18 collapse

I agree.

The only use I can see for naive date times is you just read the date out of an old sql database, but it shouldn’t leave the function naive, it should be converted first.

Python’s timezone handling is probably my only complaint about the language. I shouldn’t need to use libraries just to have timezones.