Skip to content

date: strip the O strftime modifier in the C locale - #13702

Merged
cakebaker merged 2 commits into
uutils:mainfrom
igorgbr:fix/date-o-modifier
Aug 3, 2026
Merged

cakebaker merged 2 commits into
uutils:mainfrom
igorgbr:fix/date-o-modifier

Conversation

@igorgbr

@igorgbr igorgbr commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #11656

In the C locale the O strftime modifier requests alternative numeric
symbols that do not exist, so GNU date treats it as a no-op: %Om
renders exactly like %m. jiff does not know the modifier and emitted it
literally.

Strip the modifier from the format string before jiff sees it, mirroring
the existing substitute_epoch_seconds pass. %% is preserved so that an
O following a literal percent stays plain text.

Before:

    $ LC_ALL=C TZ=UTC date -d 2024-06-15 +%Om-%Oy-%Ol
    %Om-%Oy-%Ol

After (matches GNU):

    $ LC_ALL=C TZ=UTC date -d 2024-06-15 +%Om-%Oy-%Ol
    06-24-12

The test for this behaviour already existed in tests/by-util/test_date.rs
marked #[ignore]; this PR removes the ignore.

Comment thread src/uu/date/src/date.rs
/// exist, so GNU `date` treats it as a no-op: `%Om` renders exactly like
/// `%m` (issue #11656). jiff does not know the modifier and would emit it
/// literally, so strip it before jiff sees the format string.
fn strip_o_modifier(fmt: &str) -> String {

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.

The function contains a small bug: if the input contains %%%O, the O at the end gets dropped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thanks. The root cause was broader than the trailing case:
the function assumed any O after a % was a modifier. It is only a
modifier when it actually modifies a specifier, so %O%m and %O5 were
mangled too.

Now the O is dropped only when a letter follows it. Verified byte-for-byte
against GNU date for %Om-%Oy-%Ol, %%Om, %%%O, %O, %O%m and %O5.

@cakebaker
cakebaker merged commit a730551 into uutils:main Aug 3, 2026
165 of 166 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks for your PR!

Devel08 pushed a commit to Devel08/coreutils that referenced this pull request Sep 28, 2026
* date: strip the O strftime modifier in the C locale

* date: only strip O when it modifies a specifier
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 O modifier leaks as literal in C locale

2 participants