[Datetime-SIG] Is EDT a timezone? Was: PEP-0500

Alexander Belopolsky alexander.belopolsky at gmail.com
Sat Aug 22 23:53:38 CEST 2015

On Sat, Aug 22, 2015 at 5:35 PM, Chris Barker <chris.barker at noaa.gov> wrote:

> Do pytz or datetutils let you construct a tzinfo instance from "EST" or
> the like?
> (if the answer is no -- no need to drag the thread out...)

You can discuss this on pytz or dateutils mailing lists.  The issue that I
find relevant for this group is the question I now replaced the subject
with:  Is EDT a timezone?

The answer provided by python 3.3 and later is unequivocal "yes":

>>> from datetime import *
>>> u = datetime.now(timezone.utc)
>>> t = u.astimezone()
>>> t.tzname()
>>> isinstance(t.tzinfo, timezone)
>>> print(t.tzinfo)

Some people on this list claimed that the following behavior is a bug:

>>> (t + timedelta(100)).strftime('%F %T %Z%z')
'2015-11-30 17:45:51 EDT-0400'

because the correct result should be '2015-11-30 16:45:51 EST-0500'.

My answer to that is that if you need that result, you can get it, but you
have to ask for it explicitly:

>>> (t + timedelta(100)).astimezone().strftime('%F %T %Z%z')
'2015-11-30 16:45:51 EST-0500'

I don't think we can do much here other than to educate Python users.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150822/7d5f529c/attachment.html>

More information about the Datetime-SIG mailing list