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 thread src/uu/date/src/format_modifiers.rs Outdated
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)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/csplit/csplit-heap is now passing!
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@MadeNavaneeth
MadeNavaneeth force-pushed the fix/date-strftime-composite-flags branch 2 times, most recently from c055443 to b4d5b00 Compare August 27, 2026 04:16
Comment thread src/uu/date/src/format_modifiers.rs Outdated
// 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.

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 b4d5b00 to 3e494fa Compare August 27, 2026 12:49
@MadeNavaneeth

Copy link
Copy Markdown
Contributor Author

Addressed all feedback: removed the duplicated comment and condition, shortened the is_composite_specifier doc comment to one line. The redundant check on line 238 is gone.

@MadeNavaneeth

Copy link
Copy Markdown
Contributor Author

Test already added -- test_date_format_composite_specifier_flags_issue11657 in test_date.rs. Covers both %D and %F with the - flag to verify they don't propagate into composite specifiers.

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