Skip to content

date: parse <digits>j as a local time of day#12747

Open
eyupcanakman wants to merge 1 commit into
uutils:mainfrom
eyupcanakman:fix/date-military-j-time
Open

date: parse <digits>j as a local time of day#12747
eyupcanakman wants to merge 1 commit into
uutils:mainfrom
eyupcanakman:fix/date-military-j-time

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

date -d 9j was rejected even though GNU reads it as 09:00 today. The military timezone J means local time, so a number followed by j/J (9j, 1230J) is just the bare time-of-day form. The fix strips the suffix and handles it like the bare number.

Fixes #12684.

@codspeed-hq

codspeed-hq Bot commented Jun 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 323 untouched benchmarks
⏩ 46 skipped benchmarks1


Comparing eyupcanakman:fix/date-military-j-time (832a239) with main (048f56e)

Open in CodSpeed

Footnotes

  1. 46 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.

@eyupcanakman eyupcanakman force-pushed the fix/date-military-j-time branch from 43011fa to a584e5c Compare June 9, 2026 21:24
Comment thread src/uu/date/src/date.rs Outdated
Comment on lines +425 to +432
let time_digits = match input.strip_suffix(['j', 'J']) {
Some(prefix)
if !prefix.is_empty() && prefix.chars().all(|c| c.is_ascii_digit()) =>
{
prefix
}
_ => input,
};

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 would perform the checks only once, on lines 433 - 435. It allows you to simplify the code above to something like:

Suggested change
let time_digits = match input.strip_suffix(['j', 'J']) {
Some(prefix)
if !prefix.is_empty() && prefix.chars().all(|c| c.is_ascii_digit()) =>
{
prefix
}
_ => input,
};
let time_digits = input.strip_suffix(['j', 'J']).unwrap_or(input);

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.

Done. Collapsed it to the single strip_suffix and dropped the redundant digit guard, since is_pure_digits already revalidates time_digits below.

The military timezone letter J means local time, so a time followed by j/J (9j, 1230J) is the same time-of-day form as the bare number.
GNU accepts these, but we rejected them because J was only handled as the bare string "j".
Strip the suffix and route it through the existing pure-digit path.

Fixes uutils#12684.
@eyupcanakman eyupcanakman force-pushed the fix/date-military-j-time branch from a584e5c to 832a239 Compare June 12, 2026 16:58
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout-group (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/bounded-memory is now passing!
Skip an intermittent issue tests/tail/tail-n0f (was skipped on 'main', now failing)

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: rejects <digits>j/<digits>J (time in local military timezone J) that GNU accepts

2 participants