Skip to content

LocalDateTimeRange.Split(Period) still ends early when a nanosecond period's product overflows #255

Closed

Description

@CaffeinatedCoder

Problem

#226 (fixing #219) missed a sibling. LocalDateTimeRange.Split(Period) still stops early, without an error, when the step product overflows. NodaPeriods.cs:28 computes checked(period.Nanoseconds * times), RangeSplitting.Steps reads the overflow as the end of the domain, and this call site (LocalDateTimeRange.cs:276) gets no afterPrevious fallback. PR #226 said "the temporal and NodaTime steps can't overflow on the product". That holds for Duration, ticks, days and months, but not for a Period's nanoseconds unit. Found by the final pre-release analysis on add665c (fix review, pass A).

LocalDateTimeRange.CreateFinite(0001-01-01T00:00, 9001-01-01T00:00).Split(Period.FromNanoseconds(1_000_000_000_000_000_000)) (a step of about 31.7 years) gives 10 pieces, the last [0286-03-14T16:00:00,9001-01-01T00:00:00), about 8,700 years wide. Expected: about 284 pieces, none wider than the step.

Change

Pass previous => RangeArithmetic.Checked(() => previous.Plus(step)) as the fallback. Then check every Split/Values(step) call site in core and NodaTime for a product that can overflow without a fallback.

Done when

RangeSplitOracleTests' half-domain case has a LocalDateTimeRange row with a nanosecond period, asserting every piece but the last is one step long, and it fails with the fallback removed.

Activity

  1. added this to the 10.0.0 milestone on Oct 19, 2026
  2. added
    bug
    silent
    area/ranges
    package/nodatime
    severity/medium
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/rangesbugpackage/nodatimeseverity/mediumsilent

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions