← Back to Pull requests

Dates: correct `typemin`/`typemax`, make `Date`, `DateTime`, `Timestamp` overflow-safe #63714

Open
unknown opened this pull request with 445 lines diff across 5 files
View on GitHub
unknown unknown commented on Oct 10, 2026 08:21 UTC
Author

typemax(Date) and typemin(Date) violate the interface in master:

help?> typemax
search: typemax typemin TypeVar typeof typejoin

  typemax(T)
  typemax(::T)

  The highest value representable by the given (real) numeric type T. The argument can alternatively be an
  instance of T.

julia> using Dates

julia> typemax(Date)
252522163911149-12-31

julia> typemax(Date) + Day(1)
252522163911150-01-01

The same is true for DateTime.

With this PR typemin and typemax return the representable extremes, so stepping past them wraps around like integer arithmetic. This required fixing the two limitations behind the old values:

  • The calendar accessors (year, month, day, ...) overflowed beyond about year ±2.5e14. They now split off whole 400-year cycles and compute on unsigned integers. This makes them correct for every Date and about 40% faster. Returned months and days are now always Int64, as documented.

  • Ranges with fixed steps such as Day now behave like integer ranges and no longer throw an OverflowError when their endpoints are far apart. length wraps and checked_length throws. Month and Year steps are counted exactly, which also covers the overshoot targeted by #64598, including negative steps.
  • Once the extremes are reachable, every operation near them has to be correct, so this PR also fixes the overflows found there:

  • Date(y, m, d) and DateTime(...) throw an ArgumentError for dates outside the type instead of wrapping around.

  • DateTime(::Date), unix2datetime, julian2datetime, and rata2datetime throw an InexactError instead of wrapping around.

  • floor, ceil, round, trunc, and the firstdayof…/lastdayof… adjusters throw an OverflowError when the result lies outside the type. This holds for Date, DateTime, and Timestamp.

  • Ranges with fractional steps such as Microsecond(1500) compute each element from the start, so iteration, length, indexing, and in agree and no longer come out empty or hang.
  • Performance

    The checks stay on 64-bit paths for built-in periods and widen only near the ends of the type or for huge periods. Besides the accessors:

  • isoweekdate takes about a third less time.

  • trunc to Hour, Minute, or Second takes about half the time.

  • The quarter adjusters take about 40% less time.

  • Adding Month or Quarter takes about 10% less time.

  • Timestamp rounding to a whole-tick period takes about a third less time.

  • unix2timestamp(::Rational) is much faster.

  • Fixed-step range iteration can vectorize.
  • Known limitations

  • Plain TimeType + Period arithmetic still wraps around at the ends of the type, like Int64 (#50930 is orthogonal).

  • Like for integer ranges:

  • - length of a range with more than typemax(Int) elements wraps around.
    - An empty slice cannot start at an end of the type and throws an OverflowError.
    - A typemin period step negates to itself.
  • Slices and reverse of calendar or fractional-step ranges restart at the slice's first element, so later elements can differ from r[s] (documented).

  • Some extreme Timestamp cases throw an InexactError:

  • - steps that do not fit in the tick period;
    - Timestamp + Month with wide-second ticks;
    - wide calendar ranges whose step count exceeds Int64.
  • Package TimeTypes without a guess method cannot compute the length of non-fixed-step ranges.
  • Fixes: #41082, #50931, #50981
    Supersedes: #54933

    I recommend reviewing commit-by-commit.

    Prepared with GitHub Copilot (Claude Opus 5.5).

    Diff: 445 lines (+333 / -112) across 5 files Reviewer: PatrickHaecker Review duration: 74622m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.52) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 445 lines diff across 5 files
    0.52
    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%
    44%
    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.365
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #63714"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% 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: 52.3% (MEDIUM) · Higher = larger blast radius
    52.3%
    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: 44.7% · Lower = rushed or shallow review
    44.7%
    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: 28.9% · Safe to merge
    28.9%