Skip to content

docs: a month or year shift of a short date range can be empty - #269

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
docs/259-month-shift-empty
Oct 19, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
docs/259-month-shift-empty

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #259

Problem

#223's month rule moves a LocalDateRange's start and the day after its end, and each clips to a shorter month on its own. So a short range ending on the 28th to 31st can come out with nothing between its bounds: [2024-02-28,2024-02-28].Shift(Period.FromYears(1)) is Empty. PostgreSQL gives the same answer for the daterange, and so does LocalDateTimeRange for [2024-02-28,2024-02-29). But claim R28 said Shift "keeps the shape", and the docs mentioned Empty only for a negative Expand. The maintainer decided to keep the rule and document it.

Change

  • docs/ranges.md, under "Move or widen a range":
    • The intro now reads "Both keep the shape and the inclusiveness of each bound, unless the move leaves nothing between the bounds".
    • A new bullet, "A month or year shift of a short range can give you Empty", gives the example, the PostgreSQL and LocalDateTimeRange parity, and when it happens (a range ending on the 28th to 31st, a few days long at most). It also says a whole month never empties.
  • Claims: R28's quote follows the reworded sentence, and its claim excepts the empty result. R31 names the cases. The new R45 holds them, numbered after R44 in fix: a finite bound can't land on infinity, and a closed end at the minimum moves #267.
  • DateRange has no period shifts (it steps by days), and YearMonthRange steps by whole months, so neither can empty this way. Nothing changes in code.

Tests

  • NodaTimeShiftExpandTests.LocalDateRange_ShortRangeByMonths_CanBeEmpty_AsLocalDateTimeRangeIs:
    • the analysis's cases for LocalDateRange ([2024-02-28] by P1Y, [2024-03-30] and [2024-01-29] by P1M, [2023-12-30] by P-1M) and the LocalDateTimeRange sibling
    • two non-empty controls
    • the analysis's sweep: every day from 2023-12-01 to 2025-03-31, lengths 0 to 35, steps ±1M, ±1Y and 13M. It holds each shifted LocalDateRange equal to the LocalDateTimeRange over the same days, [start, end + 1), Empty included, and asserts the sweep reaches empty results.
  • New live test CalendarShiftAgreementTests (integration). Seven rows compare LocalDateRange.Shift with PostgreSQL's daterange(start + interval, end + 1 + interval), four of which PostgreSQL empties.
  • With LocalDateRange Shift/Expand by months move the closed last day, so Month(2026,2).Shift(P1M) is not March #223's rule reverted (end.Plus(delta)), the unit test fails.
  • dotnet test: NodaTime 237, conventions 399, integration CalendarShiftAgreementTests 7, all green.

🤖 Generated with Claude Code

#223's rule moves a LocalDateRange's start and the day after its end,
and each clips to a shorter month on its own, so a short range ending on
the 28th to 31st can come out with nothing between them:
[2024-02-28,2024-02-28] moved a year is Empty. PostgreSQL gives the same
for the daterange, and LocalDateTimeRange for [2024-02-28,2024-02-29).
The maintainer kept the rule (#259); this documents it.

docs/ranges.md says when Shift returns Empty, R28's quote follows the
reworded sentence, R31 names the cases and R45 holds them.
NodaTimeShiftExpandTests pins the analysis's cases and sweeps every day
from December 2023 to March 2025, lengths 0 to 35, five steps, holding
the date range equal to the date-time range over the same days;
CalendarShiftAgreementTests asks PostgreSQL. With the old rule
restored, the unit test fails.

Closes #259

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 documentation Improvements or additions to documentation area/ranges Range unions, variants and the shape engines package/nodatime Affects CodoMetis.ValueRanges.NodaTime package/core Affects CodoMetis.ValueRanges labels Oct 19, 2026
# Conflicts:
#	test/CodoMetis.ValueRanges.NodaTime.Tests/NodaTimeShiftExpandTests.cs
#	test/oracles/claims.json
@CaffeinatedCoder
CaffeinatedCoder merged commit 59fb23e into main Oct 19, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the docs/259-month-shift-empty branch October 19, 2026 06:01
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 documentation Improvements or additions to documentation package/core Affects CodoMetis.ValueRanges package/nodatime Affects CodoMetis.ValueRanges.NodaTime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A month or year Shift of a short LocalDateRange can return Empty; R28 says Shift keeps the shape

1 participant