Skip to content

time: add IANA zoneinfo support#27832

Open
guweigang wants to merge 9 commits into
vlang:masterfrom
guweigang:time-zoneinfo-support
Open

time: add IANA zoneinfo support#27832
guweigang wants to merge 9 commits into
vlang:masterfrom
guweigang:time-zoneinfo-support

Conversation

@guweigang

@guweigang guweigang commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add IANA time zone loading to the time module through load_location, Location, Zone,
    Time.in, Time.location, and Time.zone
  • search ZONEINFO, system zoneinfo directories, V's installed zoneinfo.zip, and registered
    fallback loaders
  • add optional time.tzdata, similar to Go's time/tzdata, so embedded tzdata is opt-in instead
    of included by every time user
  • keep IANA-zoned Time values as absolute unix instants with wall-clock calendar fields for the
    selected location

Review follow-ups

  • RFC3339, HTTP-date, CBOR tag-0, and strftime handling now normalize IANA-zoned Time values
    correctly: instant formats render UTC instants, while strftime renders the zoned wall clock.
  • Importing time.tzdata on the JS backend now type-checks; the JS backend still reports
    unsupported errors for actual IANA location loading.
  • Added WASM zoneinfo/tzdata stubs so the new Location symbols are defined for that backend. WASM
    still has broader existing time/string/backend limitations, so IANA zone loading remains
    unsupported there.
  • Fixed TZ=Local on Unix-like systems so load_location('Local') does not recurse through TZ.
  • Unix Local now handles POSIX TZ strings such as EST5EDT,M3.2.0,M11.1.0, instead of treating
    every non-Local TZ value as an IANA name.
  • Windows Local now derives a POSIX-style fallback rule from GetTimeZoneInformation, so generated
    local transitions are not limited to the precomputed year window.
  • POSIX TZ tails now support M rules, Julian Jn rules, day-of-year n rules, fixed no-DST rules,
    and correct M*.5.* last-weekday transitions.
  • TZif v4 files are parsed through the same 64-bit data block and POSIX tail path as v2/v3.
  • Zoneinfo tests now pin ZONEINFO to the bundled zoneinfo.zip where deterministic data matters,
    so host OS tzdata differences do not change assertions.

Time layout / checker note

  • This PR keeps Time.loc as ?Location, not ?&Location.
  • Using ?&Location would make time.Time a pointer-containing type. That triggers the existing
    checker warning that map values containing pointers require or {} outside unsafe; CI runs
    several tool checks with -W, so that warning becomes a broad unrelated failure in tools that
    indirectly store time.Time in map values.
  • A smaller Time representation should be handled separately, likely with a non-pointer location
    handle/intern table design, instead of changing checker semantics in this zoneinfo PR.

Windows notes and current limitations

  • Windows Local uses GetTimeZoneInformation to derive the active local offset and DST transition
    rules.
  • IANA names on Windows require ZONEINFO, V's installed zoneinfo.zip, or import time.tzdata as _;
    Windows does not normally provide /usr/share/zoneinfo-style IANA files.
  • Windows abbreviation lookup currently uses the Windows standard/daylight names directly plus an
    internal abbreviation table. Unlike Go, it does not yet scan the Windows time zone registry to
    map localized names back to English Windows time zone keys, so Zone.name may be less precise on
    non-English Windows installations. Offsets and local calendar conversion are derived from the
    Windows API data.
  • Windows runtime validation was not run locally because I do not have a Windows runtime
    environment. I did run a Windows frontend/type check for the Windows-specific code path.

Backend and API limitations

  • JS and WASM define the zoneinfo API surface enough for imports/type checks, but actual
    load_location support is currently limited to the C backend.
  • time.tzdata embeds zoneinfo.zip only for the C backend. JS/WASM provide no-op package stubs
    because embedded file and full time support are not available there yet.
  • Native backend note: ./vnew -b native -check ... currently reports "The native backend has
    been removed." I did not add a native-only zoneinfo stub because the backend is unavailable, and
    the attempted native-suffix stubs are included by active backends and conflict with JS/C types.
  • register_zoneinfo_loader is intended for init/startup registration, like time.tzdata's init
    hook. It currently does not provide synchronization for registering loaders concurrently with
    load_location calls.

Validation

  • macOS at fb31cc5: ./v -g -keepc -o ./vnew cmd/v
  • macOS: ./vnew -silent test vlib/time/ => 21 passed
  • macOS: ./vnew -silent test vlib/time/tzdata/ => 1 passed
  • macOS: ./vnew -silent test vlib/encoding/cbor/tests/ => 10 passed
  • macOS: ./vnew -b js -check /tmp/time_tzdata_js_check.v
  • macOS: ./vnew -os windows -check /tmp/time_windows_zoneinfo_check.v
  • macOS: ./vnew -os cross -o /tmp/v_cross_check.c cmd/v
  • macOS: ./vnew check-md vlib/time/README.md
  • macOS tools spot checks: ./vnew -silent -N -W -check cmd/tools/vtest.v,
    cmd/tools/vbuild-tools.v, cmd/tools/vtest-self.v
  • macOS native note: ./vnew -b native -check /tmp/time_native_check.v reports
    "The native backend has been removed."
  • macOS WASM note: ./vnew -b wasm -check /tmp/time_wasm_check.v still fails on broader existing
    WASM backend limitations such as string.runes, []u8.bytestr, error(), and strings.new_builder.
  • Ubuntu Orb VM at fb31cc5 with
    VFLAGS='-gc none -cc gcc': ./v -g -keepc -o ./vnew cmd/v
  • Ubuntu Orb VM: ./vnew -silent test vlib/time/ => 21 passed
  • Ubuntu Orb VM: ./vnew -silent test vlib/time/tzdata/ => 1 passed
  • Ubuntu Orb VM: ./vnew -silent test vlib/encoding/cbor/tests/ => 10 passed
  • Ubuntu Orb VM: ./vnew -os cross -o /tmp/v_cross_check.c cmd/v
  • Ubuntu Orb VM tools spot checks: ./vnew -silent -N -W -check cmd/tools/vtest.v,
    cmd/tools/vbuild-tools.v, cmd/tools/vtest-self.v

@guweigang
guweigang marked this pull request as ready for review July 18, 2026 12:44
@GGRei

GGRei commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e432a0d57c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/time/zoneinfo.c.v
Comment thread vlib/time/tzdata/tzdata.c.v
Comment thread vlib/time/zoneinfo_nix.c.v Outdated
Comment thread vlib/time/zoneinfo_windows.c.v
Comment thread vlib/time/time.v
Comment thread vlib/time/zoneinfo.c.v Outdated
@GGRei

GGRei commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 04eca23fa0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/time/zoneinfo.c.v
Comment thread vlib/time/time.v
Comment thread vlib/time/zoneinfo_nix.c.v Outdated
Comment thread vlib/time/zoneinfo.c.v Outdated
Comment thread vlib/time/zoneinfo.c.v
Comment thread vlib/time/format.v
@GGRei

GGRei commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31662fb86c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vlib/time/zoneinfo_windows.c.v
Comment thread vlib/time/time.v
Comment thread vlib/time/zoneinfo.c.v
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.

2 participants