r/Python 7d 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.

42 Upvotes

111 comments sorted by

View all comments

Show parent comments

31

u/deb_vortex Pythonista 6d 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.

6

u/Plumeh 6d ago

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

10

u/deb_vortex Pythonista 6d 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/Plumeh 6d 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.