Skip to content

date: drop pad flags before composite strftime specifiers - #14179

Open
MadeNavaneeth wants to merge 1 commit into
uutils:mainfrom
MadeNavaneeth:date-composite-modifier
Open

date: drop pad flags before composite strftime specifiers#14179
MadeNavaneeth wants to merge 1 commit into
uutils:mainfrom
MadeNavaneeth:date-composite-modifier

Conversation

@MadeNavaneeth

Copy link
Copy Markdown
Contributor

GNU date treats composite specifiers (%D %F %T %r %R %c %x %X) as atomic, so a leading -/_ pad flag must not leak into the inner fields. jiff propagates the flag instead, so %-D produced 6/15/24 rather than GNU's 06/15/24 (issue #11657).

Add strip_modifiers_on_composite, which removes only the pad flags immediately preceding a composite letter and keeps all other modifiers (width, 0 ^ # +) so the existing huge-width guard still fires.

Fixes #11657

Comment thread src/uu/date/src/date.rs Outdated
Comment on lines +774 to +791
/// Neutralize the no-pad (`-`) and space-pad (`_`) GNU flags that sit
/// directly in front of a *composite* strftime specifier
/// (`%D %F %T %r %R %c %x %X`).
///
/// In GNU `date` these specifiers expand to a fixed sequence of simpler
/// fields (`%D` → `%m/%d/%y`, etc.) and are treated as a single atomic unit:
/// any flag applied to the composite does **not** leak into the inner fields
/// (issue #11657). jiff, however, propagates a leading `-` or `_` into those
/// inner fields, so `%-D` yields `6/15/24` instead of GNU's `06/15/24`.
/// Dropping just these pad flags before jiff sees the string makes the
/// composite render as GNU does.
///
/// Other modifiers (width digits, `0`/`^`/`#`/`+`) are deliberately left in
/// place: they do not leak into the inner fields, and they must survive so
/// the existing huge-width guard still fires for e.g. `%999999999999999999c`.
/// Only the pad flag characters `-` and `_` immediately preceding a composite
/// letter are removed; the composite itself is preserved verbatim. A dangling
/// `%` sequence is left alone.

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.

do we need such a long comment ?

Comment thread src/uu/date/src/date.rs
mod tests {
use super::*;

#[test]

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 move that into test_date.rs instead

@codspeed-hq

codspeed-hq Bot commented Aug 27, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 23.79%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 9 untouched benchmarks
⏩ 402 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation complex_relative_date 391.3 µs 316.1 µs +23.79%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing MadeNavaneeth:date-composite-modifier (5167654) with main (0d8310c)

Open in CodSpeed

Footnotes

  1. 402 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions

github-actions Bot commented Aug 27, 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/misc/tty-eof (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)
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Congrats! The gnu test tests/csplit/csplit-heap is now passing!

@MadeNavaneeth
MadeNavaneeth force-pushed the date-composite-modifier branch from e5fe803 to a283bca Compare August 27, 2026 15:23
@MadeNavaneeth

Copy link
Copy Markdown
Contributor Author

Done:

  1. Shortened the doc comment on strip_modifiers_on_composite to 4 lines
  2. Added integration test test_date_strftime_flag_on_composite in test_date.rs — un-ignored the existing test that was blocked on this fix

The unit test in date.rs tests the private function directly and can't be moved to integration tests without making it public. The new integration test covers the same behavior through the CLI.

GNU date treats composite specifiers (%D %F %T %r %R %c %x %X) as atomic,
so a leading -/_ pad flag must not leak into the inner fields. jiff
propagates the flag instead, e.g. %-D produced 6/15/24 rather than GNU's
06/15/24 (issue uutils#11657).

Add strip_modifiers_on_composite, which removes only the pad flags
immediately preceding a composite letter, and keep all other modifiers
(width, 0 ^ # +) so the existing huge-width guard still fires.

Fixes uutils#11657
@MadeNavaneeth
MadeNavaneeth force-pushed the date-composite-modifier branch from a283bca to 5167654 Compare August 27, 2026 15:43
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, …)

2 participants