Message221868
| Author |
akira |
| Recipients |
Daniel.O'Connor, akira, belopolsky, bignose, mumino, r.david.murray, santoso.wijaya, tim.peters, vstinner |
| Date |
2014年06月29日.17:58:05 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1404064685.6.0.0698458958122.issue12750@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> Can you explain why math.floor rather than builtin round is the correct function to use?
To avoid breaking existing scripts that use `.strftime('%s')` on Linux, OSX,
see msg221385:
>>> from datetime import datetime, timezone
>>> dt = datetime(1969, 1, 1, 0,0,0, 600000, tzinfo=timezone.utc)
>>> '%d' % dt.timestamp()
'-31535999'
>>> round(dt.timestamp())
-31535999
>>> dt.astimezone().strftime('%s') # <-- existing behavior
'-31536000'
>>> '%d' % math.floor(dt.timestamp())
'-31536000'
>>> import calendar
>>> calendar.timegm(dt.astimezone(timezone.utc).timetuple())
-31536000 |
|