News for hackers. Stuff that matters.
Re:Whenever – typed and DST-safe datetimes for Python by raverbashing on Sunday April 13, 2025 @09:17AM (#43672600)
Honestly yeah who in tarnation created that function and called it utcnow

These things are really frustrating

Re:Whenever – typed and DST-safe datetimes for Python by mark-r on Sunday April 13, 2025 @10:15AM (#43672964)
Yeah, utcnow is completely broken. They should have fixed it when they created datetime.timezone.utc, but they didn't. The recommendation is to use datetime.datetime.now(datetime.timezone.utc) instead. utcnow should be deprecated and eventually removed.
Re:Whenever – typed and DST-safe datetimes for Python by jessekv on Sunday April 13, 2025 @10:45AM (#43673167)
I recently learned that there is datetime.UTC which is an alias of datetime.timezone.utc

It helps a bit with the verbosity:

from datetime import datetime, UTC

datetime.now(UTC)

Re:Whenever – typed and DST-safe datetimes for Python by maleldil on Sunday April 13, 2025 @11:34AM (#43673535)
That's from 3.11 onwards.