Matt Wozniski <[email protected]> added the comment:
> I feel like "If the offset is 00:00, use Z" is the wrong rule to use
> conceptually
This is a really good point that I hadn't considered: `+00:00` and `Z` are
semantically different, and just because a datetime has a UTC offset of 0
doesn't mean it should get a `Z`; `Z` is reserved specifically for UTC.
It seems like the most semantically correct thing would be to only use `Z` if
`tzname()` returns exactly "UTC". That would do the right thing for your London
example for every major timezone library I'm aware of:
>>> datetime.datetime.now(zoneinfo.ZoneInfo("Europe/London")).tzname()
'GMT'
>>> datetime.datetime.now(zoneinfo.ZoneInfo("UTC")).tzname()
'UTC'
>>> datetime.datetime.now(datetime.timezone.utc).tzname()
'UTC'
>>> datetime.datetime.now(dateutil.tz.gettz("Europe/London")).tzname()
'GMT'
>>> datetime.datetime.now(dateutil.tz.UTC).tzname()
'UTC'
>>> datetime.datetime.now(pytz.timezone("Europe/London")).tzname()
'GMT'
>>> datetime.datetime.now(pytz.UTC).tzname()
'UTC'
I think the right rule to use conceptually is "if `use_utc_designator` is true
and the timezone name is 'UTC' then use Z". We could also check the offset, but
I'm not convinced we need to.
----------
nosy: +godlygeek
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46614>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com