Repository navigation
fix: month shifts move a date range's exclusive end, and Shift keeps infinite bounds - #238
Merged
Merged
Conversation
LocalDateRange.Shift and Expand by a period of months moved the closed last day, which NodaTime clips to a shorter month: Month(2026, 2) shifted by a month was March 1 to 28, and Quarter(2026, 3) by three months ended on December 30. LocalDateTimeRange [2026-02-01,2026-03-01) and PostgreSQL's daterange of the same month both move to all of March. The upper bound now moves as the day after it, the exclusive end PostgreSQL stores, and steps back a day, as the maintainer decided on #223: Month(y, m).Shift(P1M) is Month(y, m + 1), and the shift back restores it. A start on the 31st still clips. DateRange steps by days and YearMonthRange by whole months, where moving the end and moving the day after it agree, so neither changes. Closes #223 Found-By: CA Defect-Class: ALG Co-Authored-By: Claude Opus 5.5 <[email protected]>
On the temporal ranges the extremes stand for PostgreSQL's -infinity and infinity: Npgsql reads infinity as DateTime.MaxValue, DateOnly.MaxValue, LocalDate.MaxIsoValue and the rest, and writes them back as infinity. Shift and Expand moved such a bound like any other value, so a tsrange read from [2026-01-01,infinity), shifted back a day and saved, ended on 9999-12-30 23:59:59.999999, where PostgreSQL's upper(r) - 1 keeps infinity, and a bound at an extreme threw where infinity + 1 does not. As the maintainer decided on #224, a bound at an extreme of DateRange, DateTimeRange, DateTimeOffsetRange, LocalDateRange, LocalDateTimeRange, InstantRange or YearMonthRange now stays where it is, and so does a closed date range's end the day before the maximum, whose exclusive end the extreme is (a column holding [x,infinity) loads as [x,9999-12-30]). A finite bound moved past an extreme still throws, and the integer, float and time ranges are unchanged. RangeArithmeticOracleTests holds the rule at the edges of every infinity-backed type; InfinityShiftRoundTripTests shows it live for tsrange, tstzrange, daterange and the NodaTime columns. The seed is caught by both. Closes #224 Found-By: CA Defect-Class: STORE Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # test/CodoMetis.ValueRanges.Tests/RangeShiftExpandTests.cs
This was referenced Oct 19, 2026
LocalDateRange's day-before-max infinity rule is untested, and a minimum end counts as infinity
#257
Closed
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 #223
Closes #224
Two commits, one per issue. They touch the same
Shift/Expandcode, so they come together.Problem
LocalDateRange.ShiftandExpandby aPeriodof months moved the closed last day, which NodaTime clips to a shorter month.Month(2026, 2).Shift(P1M)was[2026-03-01,2026-03-28], andQuarter(2026, 3).Shift(P3M)ended on 30 December.LocalDateTimeRangeand PostgreSQL'sdaterangeboth move the same month to all of March.-infinityandinfinity, butShiftandExpandmoved them as ordinary values. Atsrangeread from[2026-01-01,infinity), shifted back a day and saved, ended on9999-12-30 23:59:59.999999. A bound at an extreme threw whereinfinity + 1is stillinfinity.Change
#223 (commit 1):
LocalDateRangemoves its upper bound as the exclusive end PostgreSQL stores (EndMoved: the day after, plus the period, less a day), as decided on the issue.Month(y, m).Shift(P1M) == Month(y, m + 1), the shift back restores it, and a start on the 31st still clips.DateRangesteps by days andYearMonthRangeby whole months, and there moving the end and moving the day after it agree, so neither changes. Both are pinned:YearMonthRange.Quarter(…).Shift(3)is the next quarter.#224 (commit 2):
RangeArithmetic.MoveKeepingInfinityleaves a bound that stands for an infinity where it is, as decided on the issue. Each side has its own test, per type:DateTimeRange,DateTimeOffsetRange,LocalDateTimeRange,InstantRangeMinValue/MaxValue(MinIsoValue/MaxIsoValue)YearMonthRangeDateRange,LocalDateRangeinfinity)there, because its exclusive end is the extreme: a column holding[x,infinity)loads as[x,9999-12-30](A discrete range read as [x,infinity) loses 9999-12-31; UpperBound disagrees between memory and server #117). That is the issue's first example. The lower side has no such rule, because PostgreSQL's canonical lower bound is inclusive, so0001-01-02is a real date.OverflowException. The integer, float andTimeRangetypes are unchanged.#223'sEndMovednever sees the calendar's last day now, so its special case is gone.What the live proof can and can't show
A
daterangewith an exclusiveinfinity)already comes back finite from a plain save, moved or not. It loads as[x,9999-12-30], and the plugin writes that as[x,9999-12-31). #117 settled that by documenting it, since reading it the other way broke the server's own algebra. So for that one form, the live test holds what the rule can promise: the moved row saves exactly as the unmoved row does. Every other form (tsrange/tstzrange[x,infinity),daterange[x,infinity]and[-infinity,x], and the NodaTime columns) is shown to still holdinfinityafter it is shifted and saved.docs/efcore.mdsays this.One consequence to know: with
Npgsql.DisableDateTimeInfinityConversionsset, the extremes are real dates on the server, and the rule still keeps them. The decision names the types, not the switch, so I applied it unconditionally. The InfinityDisabled integration project passes.Docs and catalogue
ShiftandExpandare new in 10.0.0, so these are fixes to something new in the same release, and CONTRIBUTING leaves those out. I refined the existingAddedlines (root, core, NodaTime) to state both rules instead.EndMovedandEndIsInfinity, theInstantRangeandYearMonthRangeextreme spellings.Tests
NodaTimeShiftExpandTestschecks every month of 2024 and 2026, both directions with a round trip, every quarter byP3M, a year byP1Y, twoExpandcases, the clipping start, andYearMonthRangequarters. With the old rule restored (end.Plus(delta)), three tests fail.RangeArithmeticOracleTests' edge rows: on the seven types whose extremes stand for an infinity, the extreme bound stays underShift(±1)andExpand(±1), andShift(1).Shift(-1)is the identity. A finite bound two steps below the maximum may move one step and throws at three.InfinityShiftRoundTripTests(integration, live): six cases, described above.shift-moves-an-infinite-bound.patchis caught on all seven types (dotnet run tools/oracles.cs seeds shift). With the seed applied, all six live tests fail too.RangeShiftExpandTests.Shift_ABoundThatStandsForInfinity_Stays. The two existing overflow asserts atDateOnly.MaxValueandDateTime.MaxValuenow start a finite bound below the extreme.dotnet test: unit 1346, NodaTime 236, EF translation 284 + 83, ASP.NET Core 92, conventions 395, integration 262, InfinityDisabled 4, all green.🤖 Generated with Claude Code