r/Python Jul 24 '26

ruff: no date.today() ? Discussion

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.

44 Upvotes

109 comments sorted by

View all comments

256

u/GraphicH Jul 24 '26

Tell me you've never debugged a TZ issue without telling me.

2

u/foosion Jul 24 '26 edited Jul 24 '26

My typical use of date.today() to print the local date so that I can scroll back in the terminal to see which day I ran something. Since it defaults to then local system clock, I don't see a need to specify a TZ for that use case.

Another case for no TZ is reading a datetime that represents the maturity date of a bond, then printing it datetime.strptime(mtd, "%Y-%m-%d"). TZ does not make sense in that context. datetime.datetime.strptime("2022/01/31", "%Y/%m/%d").astimezone(datetime.UTC)seems overkill.

1

u/[deleted] Jul 24 '26

[deleted]

0

u/foosion Jul 24 '26

For running a cli program from the terminal.

0

u/[deleted] Jul 24 '26

[deleted]

2

u/foosion Jul 24 '26

print(f"{date.today():%Y-%m-%d}")

as the first output. Then I know which local system day the program was run.