Skip to content

Preserve exact microseconds when formatting x timestamps - #1359

Closed
Eric3-jp wants to merge 1 commit into
arrow-py:masterfrom
Eric3-jp:fix/microsecond-timestamp-format-precision
Closed

Eric3-jp wants to merge 1 commit into
arrow-py:masterfrom
Eric3-jp:fix/microsecond-timestamp-format-precision

Conversation

@Eric3-jp

@Eric3-jp Eric3-jp commented Sep 22, 2026 •

Copy link
Copy Markdown

Pull Request Checklist

  • Added tests for changed code.
  • All tests pass locally on CPython 3.14.0 (Windows).
  • All repository pre-commit checks pass locally.
  • Updated documentation (the existing microsecond timestamp contract is unchanged).
  • Code is based on the current master branch.

Description of Changes

The x formatter converts a floating-point seconds timestamp to microseconds. For dates far from the Unix epoch, the float cannot preserve all six fractional digits:

import arrow

arrow.get(2500, 1, 1, 0, 0, 0, 1).format('x')
# Before: '16725225600000002'
# After:  '16725225600000001'

At datetime.max, rounding also changes 253402300799999999 to 253402300800000000, crossing beyond the end of the supported datetime range.

Compute the difference from the UTC epoch and divide it by a one-microsecond timedelta using integer division. Naive datetimes still use the local timezone, matching the previous datetime.timestamp() behavior. The X seconds formatter and timestamp parsing are unchanged.

The regressions cover positive and negative timestamps, the datetime range endpoints, UTC/non-UTC offsets (including subsecond offsets), and naive local datetimes. Four cases fail before the change.

Validation:

  • Full python -m pytest -q --tb=short: 1910 passed, 1 skipped; 99.93% total coverage with branch measurement enabled, satisfying the configured 99% gate.
  • Mypy 1.19.0: no issues in 10 source files.
  • Black 25.12.0, isort 7.0.0, and flake8 7.3.0 with the configured plugins pass for the changed files.
  • pre-commit run --all-files: all 23 repository hooks pass.
  • Full supported-interpreter tox matrix was not run locally.

OpenAI Codex assisted with the investigation, patch, tests, and this description. All listed checks were executed locally.

CI status

The initial CI run passed 24 of 25 jobs, including linting and the other interpreter/platform combinations. The Windows/PyPy 3.11 job failed during dependency installation: downloading PyYAML build dependencies raised a connection-broken IncompleteRead error, before the test suite started. Re-running that job requires repository maintainer permissions.

@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2224255) to head (48347ad).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1359   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2318    +3     
  Branches       358       359    +1     
=========================================
+ Hits          2315      2318    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@Eric3-jp Eric3-jp closed this by deleting the head repository Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant