Skip to content

fix(offset): accept DST after a standard time zone name - #343

Open
jayhemnani9910 wants to merge 3 commits into
uutils:mainfrom
jayhemnani9910:tz-dst-suffix
Open

jayhemnani9910 wants to merge 3 commits into
uutils:mainfrom
jayhemnani9910:tz-dst-suffix

Conversation

@jayhemnani9910

Copy link
Copy Markdown

The doc comment at the top of offset.rs quotes GNU's rule: "By following a non-daylight-saving time zone by the string 'DST' in a separate word (that is, separated by some white space), the corresponding daylight saving time zone may be specified." The parser doesn't do it:

$ date -u -d '2026-01-10 10:00 EST DST'      # uutils, parse_datetime 0.17.0
date: invalid date '2026-01-10 10:00 EST DST'
$ gnudate -u -d '2026-01-10 10:00 EST DST'   # GNU 9.7
Sat Jan 10 14:00:00 UTC 2026

timezone_name_offset now checks for a DST word after the zone name and adds one hour. GNU rejects DST after a zone that is already daylight saving time (EDT DST, CEST DST, ...) and after T. I got that list by trying every name in timezone_name_to_offset with DST against GNU date, and takes_dst has the same list. In those cases the word is left unparsed, so the input is invalid as before.

Testing:

  • New timezone_name_with_dst covers est dst, two spaces, utc, ist (minutes), a military letter, and the rejected forms (edt dst, t dst, estdst, est dstx). It fails without the change.
  • cargo test: all pass, one more than main. cargo clippy --all-targets and cargo fmt --check clean.
  • Compared with GNU date 9.7: every zone name in the table with DST, in four positions (after the time, before the date, between date and time, after a T time). That's 288 inputs, all the same. Also DST alone, UTC+1 DST, EST DST +1, EST DST DST, EST DST 1 hour ago and EST DST tomorrow: same.
  • Built uutils date (coreutils 865e575) against this branch: date -u -d '2026-01-10 10:00 EST DST' gives 14:00 UTC like GNU, and EDT DST is still invalid.

GNU date reads a standard time zone followed by the word DST as its
daylight saving time zone, one hour ahead: "EST DST" is EDT. The module
doc quotes that rule, but the parser rejected "2026-01-10 10:00 EST DST"
as invalid. Add the hour when DST follows a zone that takes it; after a
daylight saving time zone such as EDT, and after T, GNU rejects it, and
so does this.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 05:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.89%. Comparing base (d5c7380) to head (888c6a6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #343      +/-   ##
==========================================
+ Coverage   97.73%   98.89%   +1.16%     
==========================================
  Files          21       21              
  Lines        4421     4540     +119     
  Branches      139      142       +3     
==========================================
+ Hits         4321     4490     +169     
+ Misses         99       49      -50     
  Partials        1        1              
Flag Coverage Δ
macos_latest 98.89% <100.00%> (+1.16%) ⬆️
ubuntu_latest 98.89% <100.00%> (+1.16%) ⬆️
windows_latest 12.20% <9.54%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/items/offset.rs Outdated
let start = input.checkpoint();
let word: ModalResult<&str> =
s(take_while(1..=MAX_TZ_SIZE, AsChar::is_alpha)).parse_next(input);
if word.is_ok_and(|word| word.eq_ignore_ascii_case("dst")) {

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.

same here, word == Ok("dst") should be enough

Comment thread src/items/offset.rs Outdated

/// Whether a named timezone can be followed by DST. GNU date rejects it after
/// a daylight saving time zone, and after `t`.
fn takes_dst(name: &str) -> bool {

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.

this list duplicates names from timezone_name_to_offset
could the table carry a dst flag instead, no?

Comment thread src/items/offset.rs Outdated
/// a daylight saving time zone, and after `t`.
fn takes_dst(name: &str) -> bool {
!matches!(
name.to_ascii_lowercase().as_str(),

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 input is already lowercased in mod.rs, do we need to_ascii_lowercase here?

Comment thread src/items/offset.rs
}

#[test]
fn timezone_name_with_dst() {

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.

please add a test with a full date in tests/time.rs too, e.g. 2026-01-10 10:00 EST DST

Mark the zones that can be followed by DST in timezone_name_to_offset
instead of keeping a second list of names, and compare the next word
directly since the input is already lowercase. Test full dates with
EST DST, CET DST and IST DST, and EDT DST as invalid.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 11:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

Parse each name in the time zone table, alone and followed by DST, and
compare with GNU date 9.7, which rejects DST after the daylight saving
time zones and T.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@jayhemnani9910

Copy link
Copy Markdown
Author

Thanks. Pushed a5cc389:

  • the DST flag is now a column in the timezone_name_to_offset table, and takes_dst is gone
  • word == Ok("dst"), without lowercasing, since mod.rs already lowercases the input
  • tests/time.rs has 2026-01-10 10:00 EST DST (14:00 UTC), the lowercase form, CET DST and IST DST, and EDT DST as invalid. The expected values come from GNU date 9.7.

Also pushed 888c6a6, a test that runs every name in the table, alone and with DST, against GNU date 9.7. It covers the table rows that codecov flagged.

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