Skip to content

Carry a rounded fractional second into the next second - #1358

Open
SashaMIT wants to merge 1 commit into
python-babel:masterfrom
SashaMIT:fix/fractional-second-carry
Open

SashaMIT wants to merge 1 commit into
python-babel:masterfrom
SashaMIT:fix/fractional-second-carry

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 2, 2026 •

Copy link
Copy Markdown

Summary

format_time and format_datetime rounded a fractional second by printing an extra digit. time(0, 0, 1, 999999) with pattern ss.SSS returned 01.1000.

The timestamp is now rounded to the pattern's S width before the fields are formatted, so that second carries and the fraction stays the requested width (02.000). A pattern with no S field is left alone, and a quoted S stays literal text.

Test plan

  • time(0, 0, 1, 999999) formatted as ss.SSS is 02.000, and ss.S is 02.0
  • The same value formatted as ss stays 01, and ss 'S' stays 01 S
  • 23:59:59.999999 formatted as HH:mm:ss.SSS rolls to 00:00:00.000
  • 2020-01-01 23:59:59.999999 formatted as yyyy-MM-dd HH:mm:ss.SSS rolls to 2020-01-02 00:00:00.000
  • time(0, 0, 1, 234600) formatted as ss.SSS is 01.235 (the fraction rounds, the second does not carry)
  • Existing fractional-second cases still pass (799 microseconds as SSSS is 0008, 34567 as SSSS is 0346)

Formatting 1.999999 seconds as ss.SSS returned 01.1000. The fraction
rounded to the next second and was printed as four digits. Round the
timestamp to the pattern's S width first so the second carries and the
fraction stays within its width.

This branch has not been deployed

No deployments
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