[Datetime-SIG] PEP-0500 (Alternative datetime arithmetic) Was: PEP 495 ... is ready ...

Alexander Belopolsky alexander.belopolsky at gmail.com
Thu Aug 20 00:30:33 CEST 2015


On Wed, Aug 19, 2015 at 5:59 PM, Chris Barker <chris.barker at noaa.gov> wrote:

>
>> >>> from datetime import datetime
>> >>> datetime.strptime("2015-03-08 12:00:00-0500", "%Y-%m-%d %H:%M:%S%z")
>> datetime.datetime(2015, 3, 8, 12, 0,
>> tzinfo=datetime.timezone(datetime.timedelta(-1, 68400)))
>>
>
> semantics again -- this does indeed create an "aware" timezone, one with a
> tzinfo object with a fixed offset -- which is what ISO 8601 says it means.
>
> But anyway, I think we've only gotten tangled up in semantics here -- I
> haven't seen anything proposed about this that I have a problem with.
>

Good, so you don't have a problem understanding what "2015-03-08
12:00:00-0500" is.  Even thought New Yorkers switched to summer time early
morning of March 8, right?

Want to know what time it was in New York?  (Assuming you are not in New
York):

>>> os.environ['TZ'] = 'America/New_York'
>>> datetime.strptime("2015-03-08 12:00:00-0500", "%Y-%m-%d
%H:%M:%S%z").astimezone().isoformat()
'2015-03-08T13:00:00-04:00'

Want to know the same time in Sydney, Australia - be my guest:

>>> os.environ['TZ'] = 'Australia/Sydney'
>>> datetime.strptime("2015-03-08 12:00:00-0500", "%Y-%m-%d
%H:%M:%S%z").astimezone().isoformat()
'2015-03-09T04:00:00+11:00'

If we all understand that '2015-03-08T12:00:00-05:00',
 '2015-03-08T13:00:00-04:00' and '2015-03-09T04:00:00+11:00' are different
spellings of the same time, where is a bug in the following calculation?

>>> print(lt)
2015-03-07 12:00:00-05:00
>>> lt += timedelta(1)
>>> print(lt)
2015-03-08 12:00:00-05:00
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20150819/b98d6923/attachment.html>


More information about the Datetime-SIG mailing list