Skip to content

feat: add icu::set_default_time_zone / get_default_time_zone#2000

Open
bartlomieju wants to merge 2 commits into
mainfrom
tz/icu-set-default-time-zone
Open

feat: add icu::set_default_time_zone / get_default_time_zone#2000
bartlomieju wants to merge 2 commits into
mainfrom
tz/icu-set-default-time-zone

Conversation

@bartlomieju

@bartlomieju bartlomieju commented Jun 2, 2026

Copy link
Copy Markdown
Member

Exposes ICU's process-wide default time zone to embedders:

  • v8::icu::set_default_time_zone(&str) wraps
    icu::TimeZone::adoptDefault(icu::TimeZone::createTimeZone(id)).
  • v8::icu::get_default_time_zone() -> String returns the current
    default's IANA id.

Mirrors the existing set_default_locale / get_language_tag binding
pair in src/icu.rs and src/binding.cc.

Motivation

V8 derives its Date time zone from ICU. ICU's host detection reads the
TZ environment variable on Unix but not on Windows, where it reads
the OS/registry instead. So
DateTimeConfigurationChangeNotification(Redetect) cannot make V8 honor
TZ on Windows. With set_default_time_zone, an embedder can install the
zone explicitly from TZ and then notify isolates with
TimeZoneDetection::Skip, getting consistent cross-platform behavior that
matches Node. Downstream Deno change: denoland/deno#34705 (fixes
denoland/deno#15370).

Testing

Adds icu_default_time_zone, which sets the default zone, asserts the
getter round-trips, and checks that a fresh isolate's Date resolves the
installed zone. It uses sequential_test() because it mutates
process-global ICU state.

The new C++ in binding.cc was compiled and run against ICU 77 headers
standalone, confirming the API usage and that set/get round-trips for
America/New_York and UTC. (A full from-source cargo test wasn't run
locally; CI builds V8 from source and will exercise the binding.)

Expose ICU's default time zone so embedders can install a specific IANA
zone (e.g. from the TZ environment variable) instead of relying solely
on host detection via DateTimeConfigurationChangeNotification(Redetect).

On Windows, ICU's host detection reads the time zone from the OS and
ignores TZ, so Redetect cannot honor TZ there. set_default_time_zone
wraps icu::TimeZone::adoptDefault(createTimeZone(id)) so the requested
zone is resolved on every platform. get_default_time_zone returns the
current default's IANA id.

WIP: not yet built/tested against a full V8 build locally.
The test mutates the process-wide ICU default time zone, which affects
how other tests render Date values, so it must hold the exclusive lock
(sequential_test) rather than the shared one. Also restore the original
zone afterwards so test ordering doesn't matter.
@bartlomieju bartlomieju changed the title feat: add icu::set_default_time_zone / get_default_time_zone (WIP) feat: add icu::set_default_time_zone / get_default_time_zone Jun 2, 2026
@bartlomieju bartlomieju marked this pull request as ready for review June 2, 2026 07:39
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