Repository navigation
feat: Shift and Expand on every range type - #185
Merged
Merged
Conversation
Shift(delta) moves a range and Expand(amount) grows it on both sides, keeping each bound's inclusiveness. Each type takes its element's own step: an int, long or decimal, days for DateRange, a TimeSpan for the BCL timestamps and TimeRange, a Period for LocalDateRange and LocalDateTimeRange, a Duration for InstantRange, months for YearMonthRange. Empty and Infinite come back as they are, a negative Expand shrinks to Empty past the width, and a bound moved past the element type's extreme throws OverflowException (a TimeRange past midnight too, where TimeOnly.Add wraps). They run in memory only. Measured on PostgreSQL 18: rebuilding from lower(x) + d turns 'empty' into (,), time wraps at midnight, timestamptz + interval '1 day' adds 23 hours across a DST change in the session time zone, and infinity absorbs the step. RangeArithmeticOracleTests sweeps every discovered type against the shape matrix moved on its grid, the round-trip and hull/overlap laws, and the overflow rule; two seeds prove it. Closes #101 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # CHANGELOG.md # src/CodoMetis.ValueRanges.NodaTime/CHANGELOG.md # src/CodoMetis.ValueRanges.NodaTime/InstantRange.cs # src/CodoMetis.ValueRanges.NodaTime/LocalDateRange.cs # src/CodoMetis.ValueRanges.NodaTime/LocalDateTimeRange.cs # src/CodoMetis.ValueRanges.NodaTime/YearMonthRange.cs # src/CodoMetis.ValueRanges/CHANGELOG.md # src/CodoMetis.ValueRanges/DateRange.cs # src/CodoMetis.ValueRanges/DateTimeOffsetRange.cs # src/CodoMetis.ValueRanges/DateTimeRange.cs # src/CodoMetis.ValueRanges/DecimalRange.cs # src/CodoMetis.ValueRanges/Int32Range.cs # src/CodoMetis.ValueRanges/Int64Range.cs # src/CodoMetis.ValueRanges/README.md # src/CodoMetis.ValueRanges/TimeRange.cs # test/oracles/claims.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 #101
Problem
There was no way to move a range or grow it on both sides. "The same slot one week later" and "the booking plus 15 minutes either side" meant taking the range apart and rebuilding it, once per shape.
Change
Shift(delta)andExpand(amount)on all eleven range types, typed by the element's own step:int/long/decimalfor the numeric ranges, days (int) forDateRange,TimeSpanforDateTimeRange,DateTimeOffsetRangeandTimeRange,PeriodforLocalDateRangeandLocalDateTimeRange,DurationforInstantRange, months (int) forYearMonthRange.LocalDateTimeRangewas missing from the issue's list. It gets the same members, so the NodaTime package matches the core one.One rebuild for every type:
Internals/RangeArithmetic.Moverebuilds through the type's own factory. A discrete range canonicalizes, bounds that cross collapse toEmpty, andEmptyandInfinitecome back as they are. It is a unary operation, so the per-shape switch is over one operand, and its discard throwsShapePair.Unreachable.Overflow throws
OverflowExceptionon every type, whatever the element type throws (the BCL date types throwArgumentOutOfRangeException, whichRangeArithmetic.Checkedconverts).TimeRangeusesAddWithinDay, becauseTimeOnly.Addwraps at midnight.Runs in memory only. I measured the issue's
CASErebuild on PostgreSQL 18. Its answers differ from memory in four ways that oneCASEon the flags does not fix:int4range(lower('empty') + 1, upper('empty') + 1)is(,).'23:00'::time + interval '2 hours'is01:00, whereTimeRangethrows.SET TIME ZONE 'Europe/Berlin','2026-03-28 12:00+00'::timestamptz + interval '1 day'is2026-03-29 13:00+02. That is 23 hours, whereDateTimeOffset.Addadds 24.'infinity'::date + 1isinfinity, whereDateOnly.MaxValueoverflows.Both methods are listed in
docs/efcore.md#what-runs-wherewith these reasons.ClientSideOnlyTranslationTestsholds that they fail translation in aWhere, andClientSideOnlyProjectionTeststhat they run in memory in aSelect(claim E31).Docs: a new section in
docs/ranges.md("Move or widen a range"), the efcore row, package READMEs, changelogs under 10.0.0. Claims R28–R31, and E31 extended.Clone sweep:
DecimalRangeuseschecked(...)like the integer siblings. It is a no-op fordecimal, but it keeps the family alike. Eight waivers cover what really differs: theTimeRangemidnight rule, and the day, month andDurationstep types.Tests
RangeArithmeticOracleTests(conventions project, registered as metamorphic). It runs over every discovered range type: every shape and inclusivity of theRangeSpecsgrid, moved by whole grid steps against the moved specification. It also checksShift(d).Shift(-d) == r, thatExpand(a)containsr, thatExpand(a)is the hull ofShift(±a)andExpand(-a)their overlap, and that a bound moved past the domain's extreme throwsOverflowExceptionwhile moving away or an unbounded side does not. Its first run disagreed only because the model grew the bounds of a spec that buildsEmpty. That was the model's mistake: an empty range has no bounds. The model is fixed, not the code.dotnet run tools/oracles.cs seeds shift):shift-drops-inclusiveness.patch(11 of 12 types fail) andtimerange-shift-wraps-at-midnight.patch.RangeShiftExpandTests(core) andNodaTimeShiftExpandTests. The NodaTime tests cover month clipping, a period with a time part throwingArgumentException, andYearMonthoverflow.dotnet test: unit 1032, NodaTime 202, EF translation 253 + 81, conventions 336, ASP.NET Core 84, integrationClientSideOnlyProjectionTests, all green.🤖 Generated with Claude Code