Repository navigation
fix: LocalDateTimeRange.Split reaches the end when a nanosecond period's product overflows - #262
Merged
Merged
Conversation
…d's product overflows The #219 fix gave the step-product fallback to Int64Range, DecimalRange and the float ranges, and missed LocalDateTimeRange: a Period's nanosecond count times n leaves long while the boundary is still millennia inside the domain, NodaPeriods.Times throws, and Steps read that as the end of the domain. Split(Period.FromNanoseconds(1e18)) over nine thousand years gave ten pieces, the last 8,700 years wide. LocalDateTimeRange now passes previous.Plus(step) as the fallback. Every other Split and Values(step) call site was checked: Int32Range computes in long, and the day, month, tick and Duration products cannot pass their type's limit before the boundary passes the range's end, so none needs one. Closes #255 Found-By: CA Defect-Class: ALG Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #255
Problem
#226 (#219) gave the step-product fallback to
Int64Range,DecimalRangeand the float ranges, and missedLocalDateTimeRange.Split(Period).NodaPeriods.Timescomputeschecked(period.Nanoseconds * n), which leaveslongwhile the boundary is still millennia inside the domain, andRangeSplitting.Stepsread the overflow as the end of the domain.[0001-01-01T00:00, 9001-01-01T00:00).Split(Period.FromNanoseconds(1e18))gave 10 pieces, the last about 8,700 years wide. #226's PR said the NodaTime steps couldn't overflow on the product. That was true forDuration, ticks, days and months, but not for a period's nanoseconds.Change
LocalDateTimeRange.Split(Period)passesprevious => RangeArithmetic.Checked(() => previous.Plus(step))as the fallback. Adding nanoseconds to aLocalDateTimeis exact, so the boundaries are the same asstart + n × stepwherever that fits.Split/Values(step)call site checked. A product can overflow only ifn × steppasses its type's limit whilestart + n × stepis still inside the range. Each site's product type is listed with its limit:Int32Rangen × stepinlongintrange is far belowlongInt64Range,DecimalRange,Float64Range,Float32RangeDateRangeSplit/ValuesintDateTimeRange,DateTimeOffsetRange,TimeRangelongDateTimedomain is 3.2e18 ticks, son × stepinside the range is at most twice thatInstantRangeDurationDurationspans about 45,900 years, and theInstantdomain about 20,000LocalDateRangeSplit/ValuesPerioddays/weeks/months/years,intDateRange. A time unit throwsArgumentExceptionat the first boundaryYearMonthRangeSplit/ValuesintLocalDateTimeRangePeriodnanoseconds,longlonginside the rangeSplitis new in 10.0.0.Tests
RangeSplitOracleTests.Split_LocalDateTimeByANanosecondPeriod_ReachesTheEndis the issue's case. Every piece starts one step after the previous one's start, and the last is at most one step long. Claim R35 names it.split-nanosecond-period-ends-early.patch("10 pieces, the last starting at 0286-03-14 16:00", caught:dotnet run tools/oracles.cs seeds split-nanosecond).dotnet test: unit 1374, NodaTime 236, conventions 400, all green.🤖 Generated with Claude Code