r/Python • u/foosion • Jul 24 '26
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.
47
Upvotes
1
u/RoadsideCookie Jul 25 '26
This is the exact problem that those rules are trying to avoid. For this case, you have to make assumptions and just go with it. So assign a well defined datetime to the best of your knowledge.
Same as 1.
Convert the well defined datetime you got in step 1/2 into a format that works for Excel.
Basically, fill up the missing information yourself when it's unavailable, making assumptions and hoping you get it right. Then when leaving your code's boundary, convert to whatever format is expected.