Skip to content

date: match GNU's error for a bad --iso-8601 or --rfc-3339 value - #14305

Closed
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/date-iso8601-rfc3339-invalid-choice
Closed

date: match GNU's error for a bad --iso-8601 or --rfc-3339 value#14305
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/date-iso8601-rfc3339-invalid-choice

Conversation

@arbelonson-source

Copy link
Copy Markdown
Contributor

What

--iso-8601 and --rfc-3339 validate their value with a plain
ShortcutValueParser, so an unrecognized or ambiguous value produces
clap's own generic wording instead of GNU's.

$ date --iso-8601=bogus

# GNU
date: invalid argument 'bogus' for '--iso-8601'
Valid arguments are:
  - 'hours'
  - 'minutes'
  - 'date'
  - 'seconds'
  - 'ns'
Try 'date --help' for more information.

# uutils, before this PR
error: invalid value 'bogus' for '--iso-8601 [<FMT>]'

  [possible values: date, hours, minutes, seconds, ns]

For more information, try '--help'.

Fix

Resolve the value against each option's own choice list by hand
(matching GNU's per-option order), accepting any unambiguous
abbreviation the way GNU does, and report GNU's wording -- including
its distinct "ambiguous argument" message when the value could name
more than one choice -- when it does not resolve. Same fix already
shipped for wc --total, sort --parallel, and uniq --group/--all-repeated (#14293, #14303, #14304).

Note: date --rfc-3339 with no value supplied at all (not even an
empty string) still gets clap's own "a value is required for ... but
none was supplied" message rather than GNU's "option '--rfc-3339'
requires an argument". That's a separate, shared-infrastructure
mismatch in clap_localization.rs's handling of ErrorKind::InvalidValue
that affects other utilities too, not something specific to this
option -- left out of this PR to keep it focused.

Testing

  • cargo test -p uu_date / full tests/by-util/test_date.rs suite: 154 passed, 0 failed.
  • Added 3 regression tests asserting the exact GNU wording for an invalid --iso-8601 value, an ambiguous --iso-8601 value, and an invalid --rfc-3339 value.
  • Manually diffed every --iso-8601/--rfc-3339 value (valid, invalid, ambiguous prefix, empty) against GNU date 9.11 under LC_ALL=C.
  • cargo clippy -p uu_date --all-targets -- -D warnings and cargo fmt --check: clean.

This PR was written with AI assistance (Claude Opus 5, via Claude Code). I've tested the changes but please review the code carefully.

--iso-8601 and --rfc-3339 validated their value with a plain
ShortcutValueParser, so an unrecognized or ambiguous value produced
clap's own wording ("error: invalid value 'X' for '--iso-8601 [<FMT>]'
... [possible values: ...]") instead of GNU's ("date: invalid argument
'X' for '--iso-8601' / Valid arguments are: / ... / Try 'date --help'
for more information.").

Resolve the value against each option's own choice list by hand,
accepting any unambiguous abbreviation the way GNU does, and report
GNU's wording (and its distinct 'ambiguous argument' message) when it
does not.

AI-assisted-by: Claude Opus 5, via Claude Code
@oech3

oech3 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

see #14308 (comment)

@codspeed-hq

codspeed-hq Bot commented Aug 31, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 3.82%

⚠️ 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

⚡ 3 improved benchmarks
✅ 7 untouched benchmarks
⏩ 402 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory single_date_now 15.6 KB 15 KB +4.07%
Memory complex_relative_date 16.8 KB 16.2 KB +3.76%
Simulation single_date_now 173.7 µs 167.6 µs +3.65%

Tip

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


Comparing arbelonson-source:fix/date-iso8601-rfc3339-invalid-choice (0677f28) with main (3251833)

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

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Skip an intermittent issue tests/pr/bounded-memory (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.

3 participants