gh-90772: Add option to output UTC datetimes as "Z" in .isoformat()#131585
gh-90772: Add option to output UTC datetimes as "Z" in .isoformat()#131585StanFromIreland wants to merge 4 commits intopython:mainfrom
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.
Previous wording was correct I think: function definitions have parameters (hence ParamSpec in inspect), function calls take arguments.
OTOH text below uses argument so..
|
Seeing as Paul is against this, closing. |
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/