Repository navigation
feat: Split a range by a step or a calendar period, and Values(step) - #197
Merged
Merged
Conversation
Split(step) on every range type cuts a bounded range into consecutive pieces of one step from its start, the last clipped to the range's end and keeping its upper bound; on a continuous type the pieces are half-open, so a closed range ends [5,10] rather than [5,10), [10,10]. DateRange, LocalDateRange and YearMonthRange also split at a calendar period: range.Split(DateRange.Month), Split(DateRange.IsoWeek), or any function returning the period that holds a value, which shares the ISO week rule of #48. Values(step) on the discrete types skips ahead. Boundaries are counted from the start (a NodaTime period of months does not drift after a short month), past the domain's maximum is the end of the last piece, and the engine keeps no state, so a result enumerates alike twice. An unbounded range, a step of zero or less, or one too small to move the start (0.5m near decimal.MaxValue) throws at the call. In memory only: generate_series returns rows. RangeSplitOracleTests holds every discovered type: the pieces' union is the range, consecutive pieces are adjacent, each starts a whole number of steps from the start, the last is at most one step, Values(step) is every k-th of Values(), and the calendar split agrees across packages; two seeds prove it. Closes #100 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/ClientSideOnlyProjectionTests.cs # test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/ClientSideOnlyTranslationTests.cs # test/oracles/claims.json # test/oracles/clone-waivers.json
CaffeinatedCoder
added a commit
that referenced
this pull request
Oct 18, 2026
The closed-union copy constructor (#213), CompareTo in PostgreSQL's range order (#183), Shift/Expand (#185) and Split(step) (#197). Values(step) stays with the discrete types. Float arithmetic overflows to an infinity rather than throwing, so a moved bound or split boundary past the finite values throws OverflowException as for the other types, and a NaN or infinite step throws ArgumentException. Each split boundary is Start + n * step, rounded once. The arithmetic and split oracles gain a double grid step and an edge step of whole ulps at MaxValue, where half a grid unit is absorbed by rounding. Claims are renumbered onto the free ids after main's (E54-E57, M17, S22), with R40 and R41 for the new sentences. 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 #100
Stacked on #190 (#48, the calendar factories): the calendar split takes
DateRange.Month,IsoWeekand the rest as its period, and shares their ISO 8601 week rule. Review and merge #190 first; this PR's diff against it is the one commit.Problem
Values()walked a discrete range one element at a time, and nothing cut a range into sub-ranges. The billing months of a contract, the 30-minute slots of opening hours and the ISO weeks of a quarter were each a hand-written loop.Change
Split(step)int,long,decimal, days (DateRange),TimeSpan(DateTimeRange,DateTimeOffsetRange,TimeRange),Period(LocalDateRange,LocalDateTimeRange),Duration(InstantRange), months (YearMonthRange)Split(Func<T, TRange> period)DateRange,LocalDateRange,YearMonthRangeValues(step)Int32Range,Int64Range,DateRange,LocalDateRange(Period),YearMonthRange(months)Design decisions
DateRange.Split(DateRangeStep step). ADateRangeStep(or aCalendarUnitenum) would be one more public type on the LTS line. It would also be closed: it could never express a fiscal year or a billing cycle.Split(Func<DateOnly, DateRange> period)takes the Calendar factories for DateRange (month, quarter, year, week) #48 factories as method groups,contract.Split(DateRange.Month)andquarter.Split(DateRange.IsoWeek), so the week rule is shared by construction. It also takes any function that returns the period holding a day. A function returning a range that is unbounded or doesn't hold the day throwsArgumentException, so a bad function can't loop forever.start + n·step, not from the previous boundary. A NodaTime period of months doesn't drift: from January 31 the pieces start February 28, March 31, April 30, where repeated addition gives February 28, March 28, April 28.NodaPeriods.Timesscales aPeriodunit by unit.[0,10]split by 5 is[0,5) [5,10], not[0,5) [5,10) [10,10]. On a discrete type the cut is taken against the successor of the last value, so[1,10]split by 9 is[1,9] [10,10]. The oracle found that rule in the first draft (seed below).Values()does: an unbounded range throwsNotSupportedException. A step of zero or less throwsArgumentOutOfRangeException, as do aPeriodwith a negative unit and a step too small to move the start. Only the walk is deferred.(previous, n), so the sameIEnumerableenumerates alike twice. My first draft held the counter in a closure and did not.generate_seriesreturns rows, which is the documented reason forValues()(E31).docs/efcore.md#what-runs-wherenow listsValues(step)andSpliton that row, andClientSideOnlyTranslationTestsandClientSideOnlyProjectionTestshold both.Findings while building it
decimalnear its maximum:decimal.MaxValue - 3 + 0.5mrounds back to the start. A step belowdecimal's resolution at that size used to fail with a misleading "must move forward". It still throwsArgumentOutOfRangeException, now with a message that says why, and this is documented. A step of1mthere works.Values: two existing tests looked upGetMethod("Values"), which is ambiguous now that it has an overload. They now look the method up by name.Tests
RangeSplitOracleTests(conventions, metamorphic, registered). It runs over every discovered range type, every bounded shape and inclusivity, and steps of 1, 2, 3 and 7 grid units. It checks thatRangeSet.From(range.Split(step)) == RangeSet.From([range]), that consecutive pieces are adjacent and strictly left of each other, and that none is empty. Pieceimust startisteps from the range's start, and the last must be at most one step long.Values(step)must be every k-th ofValues(). Ranges ending at the domain maximum must split without overflow, and the rejections must come at the call. The calendar split must be one whole period per inner piece, clipped at the ends, and the same inDateRangeandLocalDateRangefor Month, Quarter, Year and IsoWeek.dotnet run tools/oracles.cs seeds split):split-stops-a-step-early.patch(the discrete cut rule) andsplit-pieces-share-their-boundary.patch(overlapping pieces).RangeSplitTestsandNodaTimeSplitTestshold the documented examples, months counted from the start, the decimal precision case, enumerating twice and the domain end.dotnet test: unit 1039, NodaTime 205, EF translation 257 + 81, conventions 339, ASP.NET Core 84, integrationClientSideOnlyProjectionTests, all green.🤖 Generated with Claude Code