Author akira
Recipients Daniel.O'Connor, akira, belopolsky, bignose, mumino, r.david.murray, santoso.wijaya, tim.peters, vstinner
Date 2014-06-26.13:15:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1403788535.25.0.475839894638.issue12750@psf.upfronthosting.co.za>
In-reply-to
Content
> I suspect that in the absence of %z, the most useful option would be to return naive datetime in the local timezone, but that can be added later.

Naive datetime in the local timezone may lose information that is contained in the input timestamp:

  >>> import os
  >>> import time
  >>> from datetime import datetime
  >>> import pytz
  >>> os.environ['TZ'] = ':America/New_York'
  >>> time.tzset()
  >>> naive_dt = datetime(2014, 11, 2, 1, 30)
  >>> naive_dt.timestamp()
  1414906200.0
  >>> naive_dt.strftime('%s')
  '1414906200'
  >>> pytz.timezone('America/New_York').localize(naive_dt, is_dst=False).timestamp()
  1414909800.0
  >>> pytz.timezone('America/New_York').localize(naive_dt, is_dst=True).timestamp()
  1414906200.0
  >>> pytz.timezone('America/New_York').localize(naive_dt, is_dst=None)
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "~/.virtualenvs/py3.4/lib/python3.4/site-packages/pytz/tzinfo.py", line 349, in localize
      raise AmbiguousTimeError(dt)
  pytz.exceptions.AmbiguousTimeError: 2014-11-02 01:30:00

1414906200 timestamp corresponds to 2014-11-02 01:30:00-04:00
but datetime(2014, 11, 2, 1, 30) along is ambiguous -- 
it may correspond to both 1414906200 and 1414909800 if local timezone is America/New_York.

It would be nice if datetime.strptime() would allow the round-trip whatever the local timezone is:

  >>> ts = '1414906800'
  >>> datetime.strptime(ts, '%s').strftime('%s') == ts

it is possible if strptime() returns timezone-aware datetime object.
History
Date User Action Args
2014-06-26 13:15:35akirasetrecipients: + akira, tim.peters, belopolsky, vstinner, r.david.murray, santoso.wijaya, bignose, Daniel.O'Connor, mumino
2014-06-26 13:15:35akirasetmessageid: <1403788535.25.0.475839894638.issue12750@psf.upfronthosting.co.za>
2014-06-26 13:15:35akiralinkissue12750 messages
2014-06-26 13:15:34akiracreate