Skip to content

fix: a finite bound can't land on infinity, and a closed end at the minimum moves - #267

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/257-260-infinity-sentinel
Oct 19, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/257-260-infinity-sentinel

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #257
Closes #260

Problem

#224 (PR #238) kept a bound that stands for an infinity where it is under Shift and Expand. The final pre-release analysis found three edges of that rule wrong or unguarded:

Change

  • RangeArithmetic.MoveKeepingInfinity: a finite bound whose moved value stands for an infinity now throws OverflowException, as decided on A Shift that lands a finite bound on the infinity sentinel keeps it there, so Shift(d).Shift(-d) != r #260, the same exception as a move past an extreme. A bound that already stands for an infinity still stays (Shift/Expand turn a bound that stands for ±infinity into a finite date #224).
  • DateRange.EndIsInfinity and LocalDateRange.EndIsInfinity drop the minimum. A closed end is infinite only at the maximum or the day before it, per the read rule (A discrete range read as [x,infinity) loses 9999-12-31; UpperBound disagrees between memory and server #117).
  • YearMonthRange: the same bug, on both sides. It used one IsInfinity for both bounds. But its last month as a start is 9999-12-01, and its first month as an end is -9998-01-31, both dates the store writes as dates. So it now has StartIsInfinity (first month only) and EndIsInfinity (last month only). [-9998-01,-9998-01].Shift(5) now moves its end. The oracle found this, beyond the issue's scope.
  • The done-when on the closed date ranges. The issue asks that [Max-3, Max-2].Shift(1).Shift(-1) == r on every type. On DateRange and LocalDateRange, though, the end's infinity starts at Max-1, so Shift(1) of [Max-3, Max-2] lands on it and throws, as decided. The tests therefore use the same row one day lower there, [Max-4, Max-3]. The issue's own example ([9999-12-01,9999-12-29].Shift(1)) now throws.
  • Docs and catalogue:
    • docs/ranges.md: a new bullet, "A finite bound can't move onto infinity", and the minimum-end note.
    • Claims: R42 is extended, R28 points to the new R44 (R43 is taken on main), and R44 is new.
    • The Shift changelog line is refined.
    • Clone waivers: YearMonthRange's per-side predicates replace two stale entries.

Tests

  • RangeArithmeticOracleTests (seven infinity-backed types). The table now records each type's first infinite end value (Max-1 for the two closed date ranges), a value two steps below it, a value two steps above the minimum, and whether a closed end at the minimum is finite. For each type:
    • one step toward an infinity and back is the identity, for Shift and Expand
    • two steps (onto it) and three (past it) throw
    • [middle, first infinite end].Shift(-1) keeps its end
    • [Min,Min].Shift(1) moves its end on DateRange, LocalDateRange and YearMonthRange
  • Seeds, all caught (dotnet run tools/oracles.cs seeds shift, … minimum-end, … localdate-day):
  • Unit tests:
    • RangeShiftExpandTests.Shift_AFiniteBoundOntoInfinity_Throws_AndOneStepShortRoundTrips and Shift_AClosedEndAtTheMinimum_Moves
    • NodaTimeShiftExpandTests.LocalDateRange_InfiniteEnds_StayAndFiniteOnesDoNotLandThere, covering LocalDateRange [x, MaxIso-1].Shift(-1d) keeping its end, the minimum end, LocalDateTimeRange, InstantRange and YearMonthRange
    • One fix: month shifts move a date range's exclusive end, and Shift keeps infinite bounds #238 assertion that moved a finite end onto 9999-12-30 now expects the throw.
  • Live: InfinityShiftRoundTripTests.Date_FiniteEndBelowInfinity_CannotBeShiftedOntoIt_AndRoundTrips. The issue's stored [2026-01-01,9999-12-30) throws on Shift(1) and round-trips unchanged through Shift(-1).Shift(1). It fails with the A Shift that lands a finite bound on the infinity sentinel keeps it there, so Shift(d).Shift(-d) != r #260 check removed.
  • dotnet test: unit 1376, NodaTime 237, EF translation 285 + 83, conventions 399, integration 266, InfinityDisabled 4, all green.

🤖 Generated with Claude Code

…inimum moves

#224 kept a bound that stands for an infinity where it is under Shift
and Expand. Two edges of that rule were wrong.

A finite bound moved onto such a value stayed there, so it saved as the
infinity and Shift(d).Shift(-d) was not the range: [9999-12-01,
9999-12-29].Shift(1).Shift(-1) was [9999-12-01,9999-12-30], and a stored
daterange [2026-01-01,9999-12-30) came back from a +1/-1 shift as
[2026-01-01,9999-12-31). As the maintainer decided on #260, that move
now throws OverflowException, as a move past an extreme does, on all
seven infinity-backed types.

A closed end at the minimum counted as -infinity, so [0001-01-01,
0001-01-01].Shift(5) did not move, though PostgreSQL's half-open form of
it is [-infinity,0001-01-02), whose upper bound is a date (#257). The
end-is-infinity test of DateRange and LocalDateRange drops the minimum,
and YearMonthRange, whose last month as a start and first month as an
end are dates too, now tests each side for its own extreme.

LocalDateRange's day-before-the-maximum rule had no test; the oracle
now holds it, with the round trip one step short of an infinity and the
moving minimum end, for every infinity-backed type. Three seeds prove
it, and InfinityShiftRoundTripTests shows the finite end live.

Closes #257
Closes #260
Found-By: CA
Defect-Class: STORE

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 19, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred area/ranges Range unions, variants and the shape engines package/nodatime Affects CodoMetis.ValueRanges.NodaTime package/core Affects CodoMetis.ValueRanges severity/medium Inconsistency or failure in a narrow scenario labels Oct 19, 2026
# Conflicts:
#	test/oracles/claims.json
@CaffeinatedCoder
CaffeinatedCoder merged commit 2942953 into main Oct 19, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/257-260-infinity-sentinel branch October 19, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ranges Range unions, variants and the shape engines bug Something isn't working package/core Affects CodoMetis.ValueRanges package/nodatime Affects CodoMetis.ValueRanges.NodaTime severity/medium Inconsistency or failure in a narrow scenario silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

1 participant