fix: serialize epoch datetimes on Windows - #242
Closed
ryanduguid wants to merge 4 commits into
Closed
Conversation
ryanduguid
marked this pull request as ready for review
August 14, 2026 10:33
tz.tzwinlocal() reports the DST rule in force today for every date, so naive pre-epoch datetimes were converted with the wrong UTC offset and output differed by platform. Serialising 1960-01-01 12:30 in Sydney gave /Date(-315613800000)/, an hour off the true instant -315610200000, while Linux read the tz database and was correct. Resolve the machine's IANA zone name instead and take the offsets from the database bundled with python-dateutil, which adds tzlocal to the runtime requirements. Epoch conversion stayed in float seconds and truncated towards zero, losing a millisecond on values that are not exactly representable and flipping the rounding direction either side of the epoch. Use integer arithmetic. Deserialisation still went through datetime.fromtimestamp, which raises OSError on Windows for pre-epoch values, so neither Xero's own /Date(-2208988800000)/ nor this branch's new output could be read back. Offset the epoch by a timedelta instead. Replace the naive pre-epoch test, which recomputed its expectation with a copy of the implementation and so could not detect the hour shift, with cases that pin a fixed timezone to known absolute instants. Add regression cases that fail without the fix: exact millisecond values either side of the epoch, pre-epoch deserialisation, and a serialise/deserialise round trip.
Author
|
Closing this as part of cleaning up an unsolicited batch I opened across several Xero repositories. I will not reopen unless a maintainer asks for a single focused change. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
datetime.timestamp()as the normal path so platform local-time, DST gap andfoldsemantics remain unchangedWhy
On Windows in a positive UTC offset, serialising
datetime.fromtimestamp(0)currently raisesOSError: [Errno 22] Invalid argumentbecause the local representation crosses before the platform epoch. The same test passes on Linux, so the existing Linux-only workflow did not expose it.Validation
git diff --check