[issue31212] datetime: min date (0001-01-01 00:00:00) can't be converted to local timestamp

Alexander Belopolsky report at bugs.python.org
Wed Aug 16 18:47:55 EDT 2017


Alexander Belopolsky added the comment:

BTW, I was originally against introducing .timestamp() method and this issue illustrates why it is problematic: people use it without understanding what it does.  If you want the distance between datetime.min and datetime(1970,1,1) in seconds - compute it explicitly:

>>> (datetime.min - datetime(1970,1,1)) / timedelta(0, 1)
-62135596800.0

If you don't want to loose precision is roundtriping between datetimes and numbers - use microseconds:

>>> (datetime.min - datetime(1970,1,1)) // datetime.resolution
-62135596800000000

It is perfectly fine to work with naive datetimes and ignore the timezone issues when all your timestamps are in one timezones, but if you choose to ignore timezones - don't use .timestamp().

----------

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


More information about the Python-bugs-list mailing list