-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tz argument to date.today() #94257
Comments
This issue is still open? I would like to solve it. |
@EltonCN As far as I know it's still open. I didn't start on an implementation yet, so have at it! |
I am not a huge fan of I also find it a tiny bit icky that I'm maybe +0 on this idea. @abalkin Any thoughts? |
This could be done after existing issues are sorted out... #88473 |
I was looking into this today and I don't think that date should have tzinfo. If you want a tz aware date datetime already offers that. I vote to keep date simple. Paul, do you want to close this? There has not been much support for it, we can always come back to it in the future. |
Feature or enhancement
Add a
tz
argument todate.today
, mirroring the interface ofdatetime.now
.Pitch
"Today" depends on the time zone, but there are many situations where you may be interested in the current date in other time zones. The most common is probably a server that runs in UTC time, but is used by people around the world.
Example use cases:
date
. This can easily lead to off-by-one errors if you don't specify the time zone.Currently, these can be implemented with
datetime.now(tz=...).date()
. While this is not a huge inconvenience, it seems like "today" and "now" both depend on the timezone, so they should both take the same inputs.Previous discussion
This was discussed in this thread on python-ideas. No one voiced any opposition, and Steven D'Aprano suggested I create an issue here.
Implementation
The python code in
datetime.py
looks fairly easy to change. Basically add something like:That may not be the most performant implementation, though it's guaranteed to pick up any bugfixes to
.now(...)
, which is desirable.I'm less familiar with the C code. The relevant piece seems to be here, which may be able to work in the same way (calling the
.now()
code). If anyone has implementation pointers, I'd appreciate it.The most difficult part seems to be adding a test case that will reliably pass whatever the local time the test is running under is.
Off the top of my head, my only idea is to pick time zones on either side of the international date line and assert that "today" in each of them differs by 1. I'm open to other suggestions for test cases.
The text was updated successfully, but these errors were encountered: