Fix Timestamp.from_datetime returning wrong value for pre-epoch datetimes by bysiber · Pull Request #662 · msgpack/msgpack-python
-
Notifications
You must be signed in to change notification settings - Fork 246
Conversation
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters