Skip to content

Add SystemDateTimeZoneSource: time zones from the platform's own database - #63

Closed
jeremy-morren wants to merge 3 commits into
evoleen:masterfrom
jeremy-morren:system-datetimezone-source
Closed

jeremy-morren wants to merge 3 commits into
evoleen:masterfrom
jeremy-morren:system-datetimezone-source

Conversation

@jeremy-morren

@jeremy-morren jeremy-morren commented Nov 6, 2026 •

Copy link
Copy Markdown

Add SystemDateTimeZoneSource: time zones from the platform's own database

Depends on #62

DateTimeZoneProviders.system is the equivalent of Noda Time's BclDateTimeZoneSource:

Platform Source IDs
Windows Win32 time zone API Windows (IANA accepted)
Linux, macOS, iOS TZif files (/usr/share/zoneinfo) IANA
Android tzdata bundle IANA
Web (JS/WASM) Browser Intl IANA
  • No fallback to the embedded data: unsupported platforms throw UnsupportedError, and unknown IDs throw DateTimeZoneNotFoundError.
  • The default zone follows TZ as DateTimeZone.local does. On Windows, IANA IDs are mapped with Windows' ICU.
  • IANA IDs work on Windows, as on .NET 6+: provider['Australia/Sydney'] maps to AUS Eastern Standard Time through Windows' ICU and keeps the requested ID. ids lists only Windows IDs.

Verified:

  • Windows matches the OS's own conversions for all 144 zones.
  • TZif matches zdump for every Linux zone.
  • Shared checks pass on Ubuntu, Windows, Chrome (JS and WASM), Node.js, Android (API 28 and 35) and iOS.

🤖 Generated with Claude Code

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Comment thread lib/src/platforms/unix_time_zone.dart Resolved
@jeremy-morren
jeremy-morren force-pushed the system-datetimezone-source branch 3 times, most recently from 22db59d to 4178823 Compare November 6, 2026 19:34
@jeremy-morren

Copy link
Copy Markdown
Author

@cursor review

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

Comment thread test_apps/.pubignore
@@ -0,0 +1,2 @@
# Apps that only CI uses (see their READMEs); not part of the published package.
*

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nested pubignore does not exclude test apps

Medium Severity

A .pubignore under test_apps/ does not affect dart pub publish. Pub only reads .pubignore at the package root, so the CI-only Flutter app (Android/iOS projects included) can still ship in the published package.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4178823. Configure here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not a bug. Pub reads .pubignore (and .gitignore) in every directory, not only at the package root. dart pub publish --dry-run lists no files under test_apps/.

case "$(readlink /etc/localtime)" in
*/zoneinfo/"$TIME_ZONE") ;;
*) echo "::error::/etc/localtime doesn't point at $TIME_ZONE"; exit 1 ;;
esac

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

iOS tests set host timezone only

Medium Severity

The iOS job rewrites the Mac's /etc/localtime and then expects the Simulator app to report Australia/Sydney. That app reads timezone files inside the Simulator, and readUnixTimeZoneId never special-cases iOS, so the host symlink does not drive systemDefaultId.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4178823. Configure here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not a bug. Simulator apps read the Mac's /etc/localtime. In our Azure Pipelines run of this job, the Mac was set to Australia/Sydney the same way, and "systemDefaultId is the configured system time zone" passed with TIME_MACHINE_EXPECT_SYSTEM_TIME_ZONE=Australia/Sydney.

@jeremy-morren
jeremy-morren force-pushed the system-datetimezone-source branch from 4178823 to b1401df Compare November 6, 2026 20:02
@jeremy-morren

Copy link
Copy Markdown
Author

@cursor review

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

# Push runs would otherwise also comment on the branch's pull request.
comment_mode: ${{ github.event_name == 'pull_request' && 'always' || 'off' }}
# Show a failure on each platform, not only on the first one.
report_individual_runs: true

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fork PRs fail the Report job

Medium Severity

The Report job's Test Results publish step always creates a check run and, on pull requests, a comment. Fork PRs still receive a read-only token, so those API calls fail and the Report job fails even when tests passed. The iOS publish step and the coverage comment already skip forks; this step does not, despite the nearby comment saying forks only get the job summary.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b1401df. Configure here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not a bug. EnricoMi/publish-unit-test-result-action detects pull_request events from forks and skips the check run and PR comment itself ("Pull request comments and check runs cannot be created, so disabling these features"). It writes only the job summary, as the workflow comment says.

…luding non-English)

On Windows, DateTimeZone.local was UTC on most systems: detection matched
DateTime.timeZoneName (a Windows display name, localized on non-English
Windows) against a hard-coded table of English names, and fell back to UTC.
Six tests failed on Windows machines outside UTC as a result.

Local zone detection now follows Noda Time, which maps .NET's
TimeZoneInfo.Local.Id:

- Windows: the Windows zone ID from GetDynamicTimeZoneInformation (via
  dart:ffi), mapped with CLDR data embedded in tzdb.bin. The ID is the
  same in every display language. With automatic DST adjustment turned
  off, the guess below is used instead.
- Linux/macOS: the IANA ID found as .NET finds it: TZ (empty means UTC,
  ':' prefix ignored, absolute paths are zoneinfo files), else the
  /etc/localtime symlink target, else the zoneinfo file with the same
  contents. Android: persist.sys.timezone.
- TZ on Windows follows Python's tzlocal and Node.js (.NET and Noda Time
  ignore it): an IANA ID, a Windows zone ID (mapped with CLDR) or a path to
  a zone file is used; empty or unrecognised values (e.g. POSIX rules)
  leave Windows' own zone.
- Otherwise: a port of Noda Time's guess by transitions, then a fixed
  zone at the current offset (no longer UTC). On Windows with automatic
  DST adjustment off, the guess uses the zone's standard offset as Windows
  reports it, not Dart's DateTime (whose C runtime applies TZ).
The abbreviation heuristic and its hard-coded name table are removed.

Embedded CLDR Windows mapping (enabling the existing compiler port):
- Check in CLDR windowsZones.xml for every version Noda Time has (21 to
  49), from unicode-org/cldr release tags; the compiler picks the newest
  suitable file and validates it against the TZDB data.
- Fix the ported CLDR parser (root element, otherVersion, splitting IDs,
  version from the file name) and MergeWindowsZones (identity-keyed map).
- NameIdMappingSupport: Russia TZ 3/10/11 and Türkiye.

Public API matching Noda Time's TzdbDateTimeZoneSource: defaultSource,
tzdbVersion, canonicalIdMap, aliases, windowsMapping, windowsToTzdbIds,
tzdbToWindowsIds and validate(); MapZone and WindowsZones are exported.

Tests: ports of Noda Time's TzdbDateTimeZoneSourceTest, MapZoneTest,
WindowsZonesTest, CldrWindowsZonesParserTest, NameIdMappingSupportTest and
ProgramTest; Windows registry and local zone tests; Unix and TZ
behaviour tests (including child processes with TZ set).

Also: version 0.15.0 (0.14.0 is already published), with a CHANGELOG
entry; require archive ^4.6.0 (XZDecoder); NOTICE references Noda Time
3.3.0, copyright to 2026.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremy-morren
jeremy-morren force-pushed the system-datetimezone-source branch from b1401df to e2b76db Compare November 6, 2026 20:16
@jeremy-morren

Copy link
Copy Markdown
Author

@cursor review

@jeremy-morren
jeremy-morren force-pushed the system-datetimezone-source branch from e2b76db to 94ad757 Compare November 6, 2026 20:19
@jeremy-morren

Copy link
Copy Markdown
Author

@cursor review

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

@jeremy-morren
jeremy-morren force-pushed the system-datetimezone-source branch 2 times, most recently from 6732881 to 94ad757 Compare November 6, 2026 20:52
…ndows; publish test results and coverage

CI only ran on Ubuntu in UTC, so it never saw platform-specific local time
zone problems (such as Windows detecting UTC). Matrix legs:

- Ubuntu: the /etc/localtime symlink.
- Ubuntu with TZ=Australia/Sydney: the TZ environment variable, with DST.
- Windows (English): the Windows zone ID mapped with CLDR, in
  AUS Eastern Standard Time (with DST).
- Windows (non-English): W. Europe Standard Time with German display
  names, as on German Windows. GitHub has no non-English runners and
  language packs can't be installed on them in reasonable time, so the
  zone's display names are set with SetDynamicTimeZoneInformation; the
  zone ID stays English, exactly as on localized Windows. A guard test
  (TIME_MACHINE_EXPECT_LOCALIZED_WINDOWS=1) fails the leg if Dart doesn't
  report the localized names.
- macOS is paused: GitHub's macOS arm64 runners are at capacity.

Also runs the TZDB compiler's tests and validates the package on every
leg, and publishes results with existing actions:

- Each leg collects LCOV coverage (lib/ only) and JSON test results,
  writes a coverage summary to its job summary (ReportGenerator) and
  uploads them as an artifact.
- A final job combines all legs: EnricoMi/publish-unit-test-result-action
  publishes a job summary, a "Test Results" check run and one PR comment
  for all platforms; ReportGenerator merges coverage into a job summary
  and an HTML artifact, posted as one PR comment
  (marocchino/sticky-pull-request-comment). Both comments are updated in
  place. Fork PRs get the job summaries only (read-only token).
- Runs on pull requests as well as pushes.

A pana job checks pub.dev platform support: it fails if pana stops
reporting any of the tags for everywhere Dart runs (the six platforms,
native AOT/JIT and web runtimes, WebAssembly, Dart and Flutter SDKs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremy-morren
jeremy-morren force-pushed the system-datetimezone-source branch from 94ad757 to f5a0ba2 Compare November 7, 2026 23:19
@jeremy-morren

Copy link
Copy Markdown
Author

@cursor review

@cursor cursor Bot 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.

Stale Bugbot comment from a previous run.

…base

The equivalent of Noda Time's BclDateTimeZoneSource (.NET's TimeZoneInfo),
exposed as DateTimeZoneProviders.system. It never falls back to the
embedded TZDB data: on a platform without time zone data it throws
UnsupportedError, and unknown IDs throw DateTimeZoneNotFoundError. Use
DateTimeZoneProviders.tzdb for data on every platform.

Backends, chosen by conditional import:
- Windows (dart:ffi): zone IDs from EnumDynamicTimeZoneInformation, rules
  for each year from GetTimeZoneInformationForYear, converted the way Noda
  Time converts adjustment rules (with fixes for rule boundaries at New
  Year and Windows' start-of-year marker transitions). Matches
  SystemTimeToTzSpecificLocalTimeEx for all 144 zones at ~1M instants.
  forId and the provider also accept IANA IDs, as .NET 6+ does: mapped to
  a Windows zone with Windows' own ICU (icu.dll), with the requested ID.
  getIds lists only Windows IDs.
- Linux, macOS, iOS: TZif v1-v4 files in $TZDIR or /usr/share/zoneinfo,
  including the POSIX TZ footer. Matches zdump for every zone.
- Android: the system tzdata bundle (APEX or /system), reusing the TZif
  parser.
The system default follows TZ as DateTimeZone.local does, so both pick the
same zone: on Linux and macOS by .NET's rules; on Windows (as Python's
tzlocal and Node.js) a Windows zone ID, or an IANA ID mapped to a Windows
zone with Windows' own ICU (icu.dll, as .NET does), with empty or
unrecognised values leaving Windows' own zone.

- Web (JS and WASM, dart:js_interop): the browser's Intl data; offsets
  from Intl.DateTimeFormat, transitions from Temporal when available or
  else by search; the standard/daylight split is inferred.

Tests: unit tests for the Windows rule conversion, TZif, the POSIX footer
and the Android bundle, comparisons against the OS (Windows) and zdump
(Linux), and shared checks (test/system_source) that run on the VM, in
Chrome (dart2js and dart2wasm), in Node, and on Android and iOS through
a Flutter integration test app (test_apps/system_source_flutter).

CI: web legs (Chrome JS, Chrome WASM, Node), Android emulators (API 35
with the APEX tzdata, API 28 with /system tzdata) and an iOS Simulator
job; web and Android results are included in the combined report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremy-morren
jeremy-morren force-pushed the system-datetimezone-source branch from f5a0ba2 to 8207100 Compare November 8, 2026 11:26
@jeremy-morren

Copy link
Copy Markdown
Author

@cursor review

@cursor cursor Bot 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.

✅ Bugbot reviewed your changes and found no new issues!

3 issues from previous reviews remain unresolved.

Fix All in Cursor

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 8207100. Configure here.

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