Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@naoNao89
Copy link
Contributor

Fixes #1882 - a 4-year-old issue where date --set failed with timezone abbreviations like AWST, EST, PST.

The Problem:
Three tests were marked "expected to fail" since 2021 because the underlying parser couldn't handle timezone abbreviations that GNU date supports.

The Solution:
Instead of hardcoding hundreds of timezones, I built a smart resolution system:

  • Only 11 truly ambiguous cases hardcoded (CST, EST, IST) following GNU's preferences
  • Dynamically discovers 588+ IANA timezones from the system
  • Lazy-loaded cache using OnceLock for zero startup cost
  • Converts abbreviations to numeric offsets before parsing

This means date --set "Sat 20 Mar 2021 14:53:01 AWST" finally works! The implementation actually goes beyond GNU by supporting additional abbreviations like Australian timezones.

Fixes uutils#1882

Implements dynamic timezone abbreviation resolution with minimal hardcoding:
- Dynamically discovers 588+ IANA timezones and their abbreviations
- Only 11 hardcoded disambiguations for truly ambiguous cases (CST, EST, IST, etc.)
- US timezone preferences for GNU compatibility
- Comprehensive test coverage including Australian, Asian, European, and US timezones

All date --set formats now work correctly.
@naoNao89 naoNao89 force-pushed the fix/issue-1882-date-set-formats branch from 4e4e8ef to 49c3386 Compare October 17, 2025 20:15
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

@naoNao89 naoNao89 force-pushed the fix/issue-1882-date-set-formats branch from 6893d9e to 16b3865 Compare October 17, 2025 20:49
@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

/// - GMT: Alias for UTC (universal)
///
/// All other timezones (AWST, JST, CET, etc.) are dynamically resolved from IANA database. // spell-checker:disable-line
static PREFERRED_TZ_MAPPINGS: &[(&str, &str)] = &[
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure we should maintain such list.
Seems that @BurntSushi has this in jiff
https://github.com/BurntSushi/jiff/blob/fdf6ab2978f49e0ac1154d78dd1c440965020506/src/fmt/rfc2822.rs#L875

maybe use that instead, no ?

Choose a reason for hiding this comment

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

Note that for Jiff, the mapping comes straight from RFC 2822. It isn't necessarily GNU compatible and it doesn't map the time zone abbreviations back to IANA time zone identifiers. Just offsets.

@sylvestre sylvestre merged commit aa172ae into uutils:main Oct 26, 2025
121 checks passed
@naoNao89 naoNao89 deleted the fix/issue-1882-date-set-formats branch October 26, 2025 18:03
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 --set is failing in freebsd

3 participants