-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-90772: Add option to output UTC datetimes as "Z" in .isoformat() #131585
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
base: main
Are you sure you want to change the base?
Conversation
Conflicts resolved and NEWS updated. Add an optional parameter to datetime.isoformat() and time.isoformat() called use_utc_designator. If provided and True and the object is associated with a tzinfo and its tzname is exactly "UTC", the formatted UTC offset will be "Z" rather than an offset from UTC.
|
cc @godlygeek Finishing off your work, I hope you don't mind :-) |
|
We deliberately chose not to do this because we did a survey of the options and it was clear that there was not an option that people would find understandable. |
|
Where was this survey done the only survey was a naming survey? The issue has overwhelming support? There was some discussion about the option naming so I can change it if there is a suggestion you consider better but the result from the naming survey didn’t receive much support in the thread itself, but I don’t mind utc_as_z. How can the only blocker be the option name? There were people who wanted it to be the default behaviour but obviously we can’t just do that so this is a step in that direction. |
|
Another possible, shorter option: datetime.isoformat(utc='z')The default would be: datetime.isoformat(utc='0') |
| .. versionchanged:: 3.6 | ||
| Added the *timespec* argument. | ||
| .. versionchanged:: next | ||
| Added the *use_utc_designator* argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous wording was correct I think: function definitions have parameters (hence ParamSpec in inspect), function calls take arguments.
OTOH text below uses argument so..
Cut down the diff removing duplicate tests (tests have been added since 2020...)
Applied Pauls suggestion from the other thread.
There was discussion about making it mandatory but that is a backwards compatibility nightmare! We can add this functionality now and in the future deprecate not using it if we wish to make it required.
Continues #32041
.isoformat()#90772📚 Documentation preview 📚: https://cpython-previews--131585.org.readthedocs.build/