mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-04-10 21:40:15 +00:00
Fix Timestamp.from_datetime returning wrong value for pre-epoch times
int() truncates towards zero, so for pre-epoch datetimes with non-zero microseconds the seconds component gets the wrong value. For example, datetime(1969, 12, 31, 23, 59, 59, 500000, UTC) has timestamp -0.5, but int(-0.5) == 0, producing Timestamp(0, 500000000) (+0.5s after epoch) instead of Timestamp(-1, 500000000) (-0.5s before epoch). Use floor division (// 1) instead, consistent with from_unix().
This commit is contained in:
parent
f9806368ae
commit
4ea42eba4d
1 changed files with 1 additions and 1 deletions
|
|
@ -167,4 +167,4 @@ class Timestamp:
|
|||
|
||||
:rtype: Timestamp
|
||||
"""
|
||||
return Timestamp(seconds=int(dt.timestamp()), nanoseconds=dt.microsecond * 1000)
|
||||
return Timestamp(seconds=int(dt.timestamp() // 1), nanoseconds=dt.microsecond * 1000)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue