Skip to content

date: fix %N modifier handling#12064

Open
dragutreis wants to merge 4 commits into
uutils:mainfrom
dragutreis:fix/date-nanosecond-modifiers
Open

date: fix %N modifier handling#12064
dragutreis wants to merge 4 commits into
uutils:mainfrom
dragutreis:fix/date-nanosecond-modifiers

Conversation

@dragutreis
Copy link
Copy Markdown

Fixes #11658

Fix %N (nanoseconds) strftime modifier handling to match GNU behavior:

  • %_3N now correctly truncates to 3 digits and right-fills trailing zeros with spaces (e.g., "0 " instead of "0")
  • %-N now correctly returns all 9 digits when no width is specified (e.g., "000000000" instead of "0")

The fix handles %N's unique semantics: width truncates from the right (not expands), _ flag right-fills with spaces, and - without width is a no-op.

Includes unit tests and integration tests.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

GNU testsuite comparison:

GNU test failed: tests/misc/user. tests/misc/user is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/nl/multiple-files. tests/nl/multiple-files is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/nl/nl. tests/nl/nl is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/cp/preserve-mode is no longer failing!
Congrats! The gnu test tests/misc/selinux is no longer failing!
Congrats! The gnu test tests/tee/tee is no longer failing!
Congrats! The gnu test tests/touch/empty-file is no longer failing!
Congrats! The gnu test tests/touch/fifo is no longer failing!
Congrats! The gnu test tests/touch/no-rights is no longer failing!
Note: The gnu test tests/cp/copy-FMR is now being skipped but was previously passing.
Note: The gnu test tests/dd/no-allocate is now being skipped but was previously passing.
Note: The gnu test tests/shuf/shuf-reservoir is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-stale-thread-mem is now being skipped but was previously passing.
Note: The gnu test tests/sort/sort-u-FMR is now being skipped but was previously passing.
Congrats! The gnu test tests/printf/printf-surprise is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@sylvestre
Copy link
Copy Markdown
Contributor

thanks
please also add a test in tests/by-util/test_date.rs

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.

date: strftime ignores flags and widths on %N (nanoseconds)

2 participants