[issue22627] Calling timestamp() on a datetime object modifies the timestamp of a different datetime object.

Alexander Belopolsky report at bugs.python.org
Wed Oct 15 03:45:11 CEST 2014


Alexander Belopolsky added the comment:

Your code as good as your timezone library, but you should realize that by discarding tzinfo you are making your "local_stamp" ambiguous.

I am not familiar with dateutil.tz, but pytz I believe uses some tricks to make sure astimezone() result remembers the isdst flag.

If you API requires naive local datetime objects, you need to carry isdst flag separately if you want to disambiguate between  2014-04-06 02:00 NZST and 2014-04-06 02:00 NZDT.  On top of that, you will not be able to use datetime.timestamp() method and will have to use time.mktime or whatever equivalent utility your timezone library provides.

Note that I was against adding datetime.timestamp() for this specific reason: it is supposed to be inverse of datetime.fromtimestamp(), but since the later is not monotonic, no such inverse exists in the strict mathematical sense.  See msg133039 in issue 2736.

BTW, if you open a feature request to add isdst=-1 optional argument to datetime.timestamp(), you will have my +1.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22627>
_______________________________________


More information about the Python-bugs-list mailing list