Skip to content

Instantly share code, notes, and snippets.

@sontek
Created September 22, 2015 04:33
Show Gist options
  • Save sontek/3351aff9e48d148910d6 to your computer and use it in GitHub Desktop.
Save sontek/3351aff9e48d148910d6 to your computer and use it in GitHub Desktop.
Python 3 can't handle dates.
from datetime import datetime
now = datetime.utcnow()
t = now.timestamp()
t2 = datetime.utcfromtimestamp(t)
assert now == t2, 'Why no work?'
@brandon-rhodes
Copy link

So during the .timestamp() operation, it is interpreting the datetime as in my local time zone, because the utcnow() call is not clever enough to attach a UTC time zone to the value it returns?

@sontek
Copy link
Author

sontek commented Sep 22, 2015

Its actually even simpler, its just a rounding bug. Its losing precision during one of the calls (I'm not sure which one). The great thing is they actually did finally fix it on Friday so whenever the next release is I should finally be able to rip out all my custom date code :)

http://bugs.python.org/issue23517

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment