Skip to content

fix: add hacky workaround for near unix time timestamps on windows #1626

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2024

Conversation

AstreaTSS
Copy link
Member

@AstreaTSS AstreaTSS commented Mar 7, 2024

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

On Windows, timestamps in the range [0, 86400) ([ being inclusive, ) exclusive) do not function properly, as seen here: python/cpython#107078
Negative 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

  • Add a negative timestamp check for fromtimestamp on Windows. This results in a clearer error than what Python would provide.
  • Add in a custom 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) to Timestamp.fromtimestamp(86399). You will need a Windows environment to test this.

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

@eightween eightween added the enhancement New feature or request label Mar 30, 2024
@eightween eightween merged commit af9866f into interactions-py:unstable Mar 30, 2024
@AstreaTSS AstreaTSS deleted the timestamp-windows-fix branch March 30, 2024 13:37
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants