Skip to content

date: reject a date string with two timezone abbreviations#12883

Merged
cakebaker merged 1 commit into
uutils:mainfrom
mistaste:fix-date-double-timezone
Jun 15, 2026
Merged

date: reject a date string with two timezone abbreviations#12883
cakebaker merged 1 commit into
uutils:mainfrom
mistaste:fix-date-double-timezone

Conversation

@mistaste

Copy link
Copy Markdown
Contributor

Summary

Fixes #12875.

date -d "EST EST" was accepted and produced a date, while GNU date rejects it:

$ date -d "EST EST"           # uutils (before): Sun Jun 14 01:00:00 AM EDT 2026
$ gnudate -d "EST EST"        # GNU: invalid date 'EST EST'

Cause

try_parse_with_abbreviation strips a trailing timezone abbreviation and parses
the remainder. For "EST EST" the remainder is the bare abbreviation "EST",
which parse_datetime resolves to "now", so the whole string was wrongly accepted.

Change

  • Factor the abbreviation lookup into resolve_tz_abbreviation.
  • After stripping the trailing abbreviation, bail out if what remains is itself a
    bare timezone abbreviation. These double-timezone inputs then fall through to the
    standard parser, which already rejects them — matching GNU.

Single and bare abbreviations are unaffected:

$ date -u -d "EST EST"                 # exit 1: invalid date 'EST EST'
$ date -u -d "EST PST"                 # exit 1: invalid date 'EST PST'
$ date -u -d "2024-01-15 10:30 EST"    # 2024-01-15 15:30:00 UTC
$ date -u -d "EST"                     # now, in EST

Checks

  • New regression test test_date_double_timezone_is_invalid; all test_date_tz_abbreviation_* tests still pass (9/9).
  • cargo fmt clean, cargo clippy -p uu_date --all-targets clean.

`date -d "EST EST"` (and similar like `EST PST`) was accepted and produced
a date, while GNU `date` rejects it as an invalid date.

The trailing-abbreviation parser stripped the last timezone token and then
parsed the remainder. For "EST EST" the remainder was the bare abbreviation
"EST", which `parse_datetime` happily resolves to "now", so the whole string
was wrongly accepted.

Factor the abbreviation lookup into `resolve_tz_abbreviation` and, after
stripping the trailing abbreviation, bail out when what remains is itself a
bare timezone abbreviation. Such double-timezone inputs then fall through to
the standard parser, which rejects them — matching GNU. A single trailing
abbreviation (e.g. "2024-01-15 10:30 EST") and a bare abbreviation (e.g.
"EST") keep working.

Fixes uutils#12875
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

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

@cakebaker cakebaker merged commit dcf5674 into uutils:main Jun 15, 2026
175 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks for your PR!

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.

gnucompability(date): when -d is "EST EST" it accepted but gnu one rejected it

2 participants