Message 413102 - Python tracker

Message413102

Author godlygeek
Recipients belopolsky, brett.cannon, eric.araujo, godlygeek, p-ganssle
Date 2022-02-11.22:16:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644617784.4.0.54442434784.issue46614@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2022-02-11 22:16:24godlygeeksetrecipients: + godlygeek, brett.cannon, belopolsky, eric.araujo, p-ganssle
2022-02-11 22:16:24godlygeeksetmessageid: <1644617784.4.0.54442434784.issue46614@roundup.psfhosted.org>
2022-02-11 22:16:24godlygeeklinkissue46614 messages
2022-02-11 22:16:24godlygeekcreate