Repository navigation
date: keep leading zeros of %N when a width is given - #15698
Merged
cakebaker merged 1 commit intoOct 24, 2026
Merged
Conversation
%3N stripped the leading zeros of the nanosecond field before truncating it, so 0.005123456 printed 512 instead of 005, and %s%3N timestamps could go backwards. Handle %N as a fraction: a width keeps the first digits and pads on the right, trailing zeros become the pad character, and the - flag drops them. This matches GNU for the flag and width combinations covered by the new test. Fixes uutils#15697
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Contributor
|
Thanks for your PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #15697
apply_modifiersstripped the leading zeros of the 9-digit%Nvalue before truncating it to the requested width. As a result,%3Nprinted512for0.005123456(GNU prints005), and consecutive%s%3Ntimestamps could go backwards.%Nis a fraction, not an integer, so it now goes through its own small helper:widthdigits, leading zeros included;%12Ngives005123456000, not000005123456);%_3Nof.050gives05), and the-flag drops them (%-3Ngives05);%N,%-Nand%+Nstay 9 digits, and%_Nspace-pads the trailing zeros as before.The two
%N-only branches left in the generic padding path could no longer be reached, so I removed them.Testing
date9.7 on 24 flag/width combinations (%N %3N %_3N %-3N %_N %-N %12N %_12N %03N %+3N %^3N %1N %-9N %-12N %_-3N %-_3N %_03N %0_3N %+N %+12N %_+3N %0N %_9N %9N), each at@0.005123456,@0.123,@0and@0.05. All outputs match. Before this change, 13 of them differed.test_date_strftime_n_width_keeps_leading_zerosintests/by-util/test_date.rs. It fails onmainand passes with this change.cargo test --features date --no-default-features -- test_date(193 passed),cargo test -p uu_date(42 passed), andcargo clippy --all-targets -- -D warningsfor thedatefeature are all clean.I used an AI assistant to help write this change. I reviewed every line, and I worked out the expected outputs by running GNU
dateas a black box, not from its source.