Repository navigation
date: drop pad flags before composite strftime specifiers - #14179
MadeNavaneeth wants to merge 2 commits into
Conversation
| /// 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. |
There was a problem hiding this comment.
do we need such a long comment ?
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
please move that into test_date.rs instead
Merging this PR will degrade performance by 1.07%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | three_39_bit_primes |
381.6 ms | 445.4 ms | -14.32% |
| ❌ | Simulation | thirteen_39_bit_primes |
8.6 s | 9 s | -4.26% |
| ⚡ | Simulation | five_38_bit_primes |
1.9 s | 1.6 s | +18.05% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing MadeNavaneeth:date-composite-modifier (6406fb4) with main (6808452)
Footnotes
-
54 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. ↩
|
GNU testsuite comparison: |
e5fe803 to
a283bca
Compare
|
Done:
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. |
a283bca to
5167654
Compare
|
with your PR, %_10T now prints 0007:08:09 vs GNU's 07:08:09; that's a real behaviour regression |
| chars.next(); | ||
| } | ||
| out.push('%'); | ||
| out.push(chars.next().unwrap()); |
There was a problem hiding this comment.
please remove the unwrap()
| out | ||
| } | ||
|
|
||
| /// Neutralize the no-pad (`-`) and space-pad (`_`) GNU flags that sit |
There was a problem hiding this comment.
this is a too long commit and isn't smooth
please make it shorter
|
One edge case before
The upstream change behind this is scoped to
Same Measured on GNU 9.7 (Ubuntu 26.04). |
|
Thanks for the review feedback. I narrowed the composite rewrite to %D only, so %F and %T keep their GNU modifier semantics. I also added regression coverage for the reported cases: %-D on a normal date, %-F on year 0001 (0001-01-01), and %_10T (two leading spaces before 07:08:09). The date unit suite (36 tests) and the targeted integration test pass locally, and the branch is updated. |
|
Caught a
|
244c56f to
4732101
Compare
GNU treats %D as atomic, so its pad flags never reach the inner %m/%d
fields: `date +%-D` prints 06/15/24, not 6/15/24. Drop the pad flags
before a composite specifier and leave the width and the other modifiers
alone.
The other composites are not atomic, and they need their own handling:
%-F keeps the padding of the year, so `%-F` on 0001-01-01 stays
0001-01-01 rather than losing the year padding
%T is expanded by jiff with a single-digit hour left unpadded, so put
the zero back before any width or flag is applied
The `%%` literal and a trailing `%` are left untouched, and an absurd
width is still rejected rather than truncated.
4732101 to
ab15db6
Compare
|
All four addressed, and the branch is now a single commit (was three, which is what "not smooth" was about):
|
|
Hi — this fixes #11657, which also has #11752 open. Flagging in case you'd prefer to The change defers zero-padding until composite specifiers ( Tests cover the three marker forms and include a regression guard that all twelve |
|
Correction to my comment above — it described an earlier draft of this PR, not what the What I wrote was that padding is deferred until composite specifiers are expanded, with a The current commit (
Tests are the three cases above plus non-composite specifiers keeping their modifiers So: single specifier, not twelve. Apologies for the crossed wires. |
The hour correction was keyed to `%T` with a hard-coded length, so a space-pad flag on another time composite stripped the hour's zero padding and nothing put it back: %_R -> 7:08 (GNU: 07:08) %_10R -> " 7:08" (GNU: " 07:08") %_r -> 7:08:09 AM (GNU: 07:08:09 AM) Unflagged %R was already correct and is now covered too. A single digit followed by ':' can only be an unpadded hour, so match the shape instead of one composite's length. The existing %_10T case is unaffected.
Unable to generate the flame graphsThe performance report has correctly been generated, but there was an internal error while generating the flame graphs for this run. We're working on fixing the issue. Feel free to contact us on Discord or at [email protected] if the issue persists. |
|
On Current main matches GNU coreutils 9.12. At |
GNU renders the
%D,%Fand%Tcomposites atomically, but jiff expands them field by field and lets the pad flags reach the inner fields, so%-Dproduced6/15/24rather than GNU's06/15/24(issue #11657).Three separate problems, three separate fixes:
%D—strip_modifiers_on_compositedrops the pad flags immediately before aDspecifier and keeps every other modifier, so the existing huge-width guard still fires. The other composites are not handled here, because GNU does not treat them the same way.%F— the year is padded internally, so the flag must not strip that padding.%-Fon0001-01-01stays0001-01-01.%T— jiff leaves a single-digit hour unpadded, so the leading zero is put back before any width or flag is applied.%%literals and a trailing%are left alone, and an absurd width is still rejected rather than truncated.Fixes #11657