fix: add hacky workaround for near unix time timestamps on windows #1626
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.
Pull Request Type
Description
On Windows, timestamps in the range [0, 86400) (
[
being inclusive,)
exclusive) do not function properly, as seen here: python/cpython#107078Negative values have straight up never worked on Windows either, but it results in a weird error.
This PR does a bit of trickery to get the timestamps in the range of [0, 86400) working on Windows, at least to an extent where it doesn't error and is mostly correct.
Changes
fromtimestamp
on Windows. This results in a clearer error than what Python would provide.astimezone
function that makes timestamps in the range [0, 86400) work correctly with it. It does this by using the timezone of a slightly later date.Related Issues
A more proper fix to one part of #1625. It's not a complete fix for the bug that caused the PR in the first place (since
ActivityTimestamp
's parsing results in incorrect behavior), but it'll make things not error out, at least.Test Scenarios
Timestamp.fromtimestamp(0)
toTimestamp.fromtimestamp(86399)
. You will need a Windows environment to test this.Python Compatibility
3.10.x
3.11.x
Checklist
pre-commit
code linter over all edited files