Add the `zoneinfo` module

SA
1mo ago
+964-63

Adds the zoneinfo module and integrates ZoneInfo into datetime.

ZoneInfo(key) resolves an IANA key against the tz database the worker already carries (jiff's bundled tzdb, the same source OsPolicy::timezone uses), with CPython's key validation and ZoneInfoNotFoundError message.
available_timezones() returns the set of keys; ZoneInfo.no_cache() and ZoneInfo.clear_cache() exist for compatibility.
utcoffset(dt), tzname(dt), dst(dt) and fromutc(dt) follow CPython; a wall clock in a DST gap takes the pre-transition offset, as CPython's fold=0 does.

In datetime, a ZoneInfo works as tzinfo for construction, replace, combine, now(tz), astimezone, utcoffset/tzname/dst, timetz() and timedelta arithmetic.
The offset and abbreviation in force at each wall clock are resolved on demand and the zone object stays as dt.tzinfo.
Two datetimes sharing a tzinfo object subtract and compare by wall clock, as in CPython.

monty-types gains SandboxTimeZone::dst_seconds, available_names and info_for_local to back this.

Divergences recorded in limitations/zoneinfo.md and limitations/datetime.md:

  • ZoneInfoNotFoundError is bound to KeyError
  • no instance cache: ZoneInfo('UTC') is ZoneInfo('UTC') is False (== is by key)
  • ZoneInfo.from_file() is not implemented; reset_tzpath / TZPATH are absent
  • datetime.now(ZoneInfo(...)) under the CallHost clock policy raises NotImplementedError
  • time(tzinfo=ZoneInfo(...)) raises TypeError, since a time has no date to resolve the zone
  • fold is not read, so ambiguous wall clocks resolve to the first occurrence
  • keys are case-sensitive
  • dst() is approximated as the difference from the zone's standard offset that year

Module registered in limitations/modules.md, docs/limitations/index.md, SANDBOX_MODULE_NAMES, the JS external-module list and binary_serde.rs; the Type fingerprint and builtin_type_serialization.txt fixture are extended.

Tests in zoneinfo__module.py (skip-cpython-windows, which has no time.tzset) plus additions to the datetime cases.
Part of the set of PRs for the stdlib gaps reported by a user running Monty as an agent code-mode sandbox.

šŸ¤– Generated with Claude Code

https://claude.ai/code/session_018zfZ5wd33kjDtV7BoUUV2T


Summary by cubic

Adds the zoneinfo module with ZoneInfo and available_timezones(), and integrates ZoneInfo as a tzinfo for datetime. Offsets and abbreviations are resolved on demand from the worker's bundled tz database, and datetimes sharing a ZoneInfo object subtract and compare by wall clock, as in CPython.

Notable divergences:

  • ZoneInfoNotFoundError is KeyError; there is no instance cache, from_file(), TZPATH, or reset_tzpath(), and clear_cache() is a no-op.
  • fold is ignored, ambiguous wall clocks take the first occurrence, and dst() is approximated from the year's standard offset.
  • datetime.now(ZoneInfo(...)) raises NotImplementedError under the call_host clock policy.
  • time(tzinfo=ZoneInfo(...)) raises TypeError, since a bare time has no date to resolve the zone.
  • A ZoneInfo cannot cross the host boundary; an aware datetime is serialized with the fixed offset and abbreviation in force at that instant.