Skip to content

date: skip '-' flag for composite strftime specifiers - #14163

Open
MadeNavaneeth wants to merge 1 commit into
uutils:mainfrom
MadeNavaneeth:fix/date-strftime-composite-flags
Open

date: skip '-' flag for composite strftime specifiers#14163
MadeNavaneeth wants to merge 1 commit into
uutils:mainfrom
MadeNavaneeth:fix/date-strftime-composite-flags

Conversation

@MadeNavaneeth

Copy link
Copy Markdown
Contributor

Summary

Fixes #11657

The problem

GNU date treats composite strftime specifiers (%D, %F, %T, %r, %R, %c, %x, %X) as atomic: flags like - apply to the whole expansion, not to inner sub-fields. uutils let the - flag propagate into inner specifiers:

$ LC_ALL=C TZ=UTC date -d "2024-06-15" "+%-D"
06/15/24    # GNU: correct
6/15/24     # uutils: wrong (strips leading zero from %m)

The fix

Strip the - flag from composite specifiers before applying modifiers, so inner fields keep their default padding while width and other flags still work.

Verification

  • ✅ 140/140 date tests pass
  • %-D now correctly outputs 06/15/24 (matching GNU)

Comment on lines +239 to +249
// GNU treats composite specifiers (D, F, T, r, R, c, x, X)
// as atomic: the `-` flag applies to the whole expansion,
// not to inner sub-fields. Since jiff already expands them
// correctly, strip the `-` flag so apply_modifiers doesn't
// remove leading zeros from inner fields like %m in %D.
if !parsed.flags.is_empty() || parsed.width.is_some() {
// GNU treats composite specifiers (D, F, T, r, R, c, x, X)
// as atomic: flags like `-` apply to the whole expansion,
// not to inner sub-fields. Since jiff already expands them
// correctly, strip the `-` flag so apply_modifiers doesn't
// remove leading zeros from inner fields like %m in %D.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think it needs 10 lines of comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make this comment shorter

@sylvestre

Copy link
Copy Markdown
Contributor

needs a test too

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)

@MadeNavaneeth
MadeNavaneeth force-pushed the fix/date-strftime-composite-flags branch from 8ecdcf5 to c055443 Compare August 27, 2026 00:21
GNU date treats composite strftime specifiers (%D, %F, %T, %r, %R, %c,
%x, %X) as atomic: flags like '-' apply to the whole expansion, not to
inner sub-fields. uutils let the '-' flag propagate into inner specifiers,
producing e.g. '6/15/24' for %-D instead of '06/15/24'.

Strip the '-' flag from composite specifiers before applying modifiers,
so inner fields keep their default padding while width and other flags
still work.

Fixes uutils#11657
@MadeNavaneeth
MadeNavaneeth force-pushed the fix/date-strftime-composite-flags branch from c055443 to b4d5b00 Compare August 27, 2026 04:16
// not to inner sub-fields. Since jiff already expands them
// correctly, strip the `-` flag so apply_modifiers doesn't
// remove leading zeros from inner fields like %m in %D.
if !parsed.flags.is_empty() || parsed.width.is_some() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is identical to the condition on line 238.

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 flags propagate into composite specifiers (%-D, %-F, …)

3 participants