Skip to content

fix(date): accept HH:MM date-times and zone suffixes in -d - #2662

Open
xmakro wants to merge 1 commit into
everruns:mainfrom
xmakro:fix/date-iso-datetime
Open

xmakro wants to merge 1 commit into
everruns:mainfrom
xmakro:fix/date-iso-datetime

Conversation

@xmakro

@xmakro xmakro commented Oct 9, 2026

Copy link
Copy Markdown

What changed

date -d now accepts ISO date-times without seconds and with a zone. touch -d and find -newermt share the parser and gain the same forms.

  • YYYY-MM-DD HH:MM (with T or a space), and an optional fraction after the seconds
  • a trailing UTC/GMT, Z, or a numeric offset (+0200, +02:00, -05), so git's %ci output parses

The change is a few more chrono formats next to the existing ones; chrono validates the fields and the offset range.

Why

Only YYYY-MM-DD and YYYY-MM-DD HH:MM:SS without a zone were accepted, so common inputs such as a minute-precision timestamp, a UTC log line or a git commit date failed with invalid date.

Before / After

$ date -u -d '2026-10-08 14:30' '+%F %T'
Before: date: invalid date '2026-10-08 14:30'
After:  2026-10-08 14:30:00

$ date -u -d '2026-10-08 14:30:15 UTC' '+%F %T'
Before: date: invalid date '2026-10-08 14:30:15 UTC'
After:  2026-10-08 14:30:15

$ date -u -d '2026-10-08 14:30:15 +0200' '+%F %T'
Before: date: invalid date '2026-10-08 14:30:15 +0200'
After:  2026-10-08 12:30:15

Every After line matches GNU date 9.12. Compared with GNU on 31 date-time inputs in UTC and America/Los_Angeles: the only differences are rare forms this still rejects (a comma fraction 14:30:15,5, an exact -2400 offset, 2026-10-08Z), and 12:30:60, which bashkit already accepted before this change.

Risk

  • Low
  • Inputs that failed before now parse; inputs that parsed before parse the same way.

Checklist

  • Tests added or updated: unit tests, spec cases in date.test.sh, three rows in the GNU date differential test
  • Backward compatibility considered

`date -d` (and `touch -d`, `find -newermt`, which share the parser)
only took ISO dates with full seconds and no zone. It now also reads
`YYYY-MM-DD HH:MM`, an optional fraction of a second, and a trailing
`UTC`/`GMT`, `Z` or numeric offset (`+0200`, `+02:00`, `-05`),
which covers git's `%ci` format.

This branch has not been deployed

No deployments
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.

1 participant