On 08/24/2015 10:16 AM, Alexander Belopolsky wrote:> PEP 495 takes a different 
approach:

>>> from test.datetimetester import Eastern2
>>> datetime(2004, 4, 4, 2, first=True, 
tzinfo=Eastern2).astimezone().isoformat()
'2004-04-04T03:00:00-04:00'
>>> datetime(2004, 4, 4, 2, first=False, 
tzinfo=Eastern2).astimezone().isoformat()
'2004-04-04T01:00:00-05:00'

A post-PEP 495 timezone conversion faced with a missing time is required to 
return
 a valid time.  This is similar to the way C mktime works in most 
implementations.
If you give it a struct tm representing a time from a DST gap - it will 
"normalize"
 it by changing tm_hour up or down depending on the tm_isdst value.

I would be much happier about this if:

 >>> datetime(2004, 4, 4, 2, first=None, 
tzinfo=Eastern2).astimezone().isoformat()
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File ".../pytz/tzinfo.py", line 327, in localize
     raise NonExistentTimeError(dt)
 NonExistentTimeError: 2004-04-04 02:00:00

Giving the programmer an easier option to use if they want an exception.

--
~Ethan~
_______________________________________________
Datetime-SIG mailing list
[email protected]
https://mail.python.org/mailman/listinfo/datetime-sig
The PSF Code of Conduct applies to this mailing list: 
https://www.python.org/psf/codeofconduct/

Reply via email to