Skip to content

Format X token as integer seconds (#933)#1297

Open
vineethsaivs wants to merge 1 commit into
arrow-py:masterfrom
vineethsaivs:fix/format-x-token-integer-seconds
Open

Format X token as integer seconds (#933)#1297
vineethsaivs wants to merge 1 commit into
arrow-py:masterfrom
vineethsaivs:fix/format-x-token-integer-seconds

Conversation

@vineethsaivs

Copy link
Copy Markdown

Issue Description

Fixes #933.

The X (Unix timestamp) format token returned f"{dt.timestamp()}", which is a float:

>>> arrow.Arrow(2021, 3, 1, 0, 1, 47, 369226).format("X")
'1614556907.369226'      # before
>>> arrow.Arrow(2021, 3, 1, 0, 1, 47, 369226).format("XSSS")
'1614556907.369226369'   # before: stray dot + extra digits

format("X") leaked the fractional part, and composite tokens like XSSS produced a stray dot and trailing digits. As noted in the issue, this was a regression from 0.17.0, which emitted whole seconds.

Fix

Return integer seconds (int(dt.timestamp())), matching the documented X token (Unix timestamp) and the pre-1.0 behavior:

>>> ...format("X")
'1614556907'
>>> ...format("XSSS")
'1614556907369'

Parsing is unaffected (arrow.get("1614556907", "X") still round-trips, and the parser still accepts fractional timestamps).

Tests

Updated tests/test_formatter.py::test_timestamp to assert whole-second output for X (it previously asserted the float). All 623 formatter tests pass.


Disclosure: prepared with AI assistance; reviewed by me and I can explain every line.

The `X` (Unix timestamp) format token returned `f"{dt.timestamp()}"`, a float
like `1614556907.369226`, so `format("X")` leaked a fractional part and tokens
such as `XSSS` produced a stray dot and extra digits (e.g.
`1614556907.369226369`). This was a regression from 0.17.0, which emitted whole
seconds.

Return integer seconds (`int(dt.timestamp())`), matching the documented token
and pre-1.0 behavior. `XSSS` now yields `1614556907369` again.

Fixes arrow-py#933

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 13, 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 (4142ad8).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1297   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         2315      2315           
  Branches       358       358           
=========================================
  Hits          2315      2315           

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

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.

format XSSS outputs too many digits and a dot

1 participant