← Back to Pull requests

Add the `zoneinfo` module #1176

Open
unknown opened this pull request with 572 lines diff across 7 files
View on GitHub
unknown unknown commented on Oct 29, 2026 04:11 UTC
Author

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

    <!-- This is an auto-generated description by cubic. -->
    ---

    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.
  • <sup>Written for commit 2f708f6e792883ae9cf99ce526db2e873c20f4f5. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1176?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/pydantic/monty/1176?returnTo=https%3A%2F%2Fgithub.com%2Fpydantic%2Fmonty%2Fpull%2F1176&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 572 lines (+429 / -143) across 7 files Reviewer: samuelcolvin Review duration: 46772m
    All Vouch review confidence checks passed
    Residual risk 0.34 = Change Risk (0.57) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 572 lines diff across 7 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.380
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1176"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 56.8% (MEDIUM) · Higher = larger blast radius
    56.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 33.5% · Safe to merge
    33.5%
    Repository