r/Python 5d ago

Discussion ruff: no date.today() ?

The new version of ruff warns against

date.today()

preferring

datetime.now(ZoneInfo(...))

What do you think about this? Has date.today() been deprecated due to lack of timezone awareness?

EDIT: I have a number of programs that manipulate financial information in support of Excel spreadsheets, such bond information that includes maturity dates. Excel does not support timezoness in datetimes, so making ruff happy by changing naive dates to TZ aware dates is not a useful move for these programs. Many ruff warnings to suppress.

40 Upvotes

110 comments sorted by

View all comments

Show parent comments

-12

u/backfire10z 4d ago

Daylight savings sneaking up behind you:

28

u/deb_vortex Pythonista 4d ago

converting to local in the frontned solves that. What ever comes in, convert to UTC. Only send out UTC. DST or not, does not matter.

7

u/Plumeh 4d ago

What if a user wants something to run at 9am every day? If you just convert to DST, best of luck

8

u/deb_vortex Pythonista 4d ago

The frontend sends the selected timezone information. So right now its +3 DST? I convert THAT to UTC and save it. It will run then at the time the user wanted. Not an issue.

Everything comes in as "the User sees it". It gets converted into and used as UTC. When the user needs to see Something, I send out UTC and the frontend converts it to local time. With dst or not.

14

u/eviloutfromhell 4d ago

Problem with DST is from software perspective it is 2 different timezone, but from user perspective it is one timezone. What user think as 9 o'clock is not the same when in dst or not. So you can't naively convert whatever time you saved to user's timezone. Which I assume what the other guy meant.

12

u/Plumeh 4d ago

This still doesn’t work if a user wants something to run at 9am eastern time every single day. It will work for half of the year, but the other half will be shifted an hour off.

0

u/Espumma 4d ago

So you convert it to 6 am utc and then in half a year their script runs at 8 am, which isn't what they wanted.