Skip to content

LocalDateRange Shift/Expand by months move the closed last day, so Month(2026,2).Shift(P1M) is not March #223

Closed

Description

@CaffeinatedCoder

Problem

LocalDateRange.Shift and Expand by a Period of months move the closed last day, so a month does not shift to the next month:

  • LocalDateRange.Month(2026, 2).Shift(Period.FromMonths(1)) is [2026-03-01,2026-03-28], not Month(2026, 3).
  • Quarter(2026, 3).Shift(P3M) ends on 30 December.
  • Month(2026, 2).Expand(P1M) is [2026-01-01,2026-03-28].

The sibling LocalDateTimeRange [2026-02-01,2026-03-01).Shift(P1M) is [2026-03-01,2026-04-01), and PostgreSQL's own arithmetic on the daterange [2026-02-01,2026-03-01) gives [2026-03-01,2026-04-01). Claim R31 names both types in one sentence, yet they disagree on the same month. The calendar factories (#48) ship in the same release, so Month(...).Shift(P1M) is the obvious call to write. Found by the pre-tag analysis (#179) at LocalDateRange.cs:527,541. The same rule probably applies to DateRange and YearMonthRange with any month-based step; check every closed-end date type.

Decision (maintainer, 2026-10-18)

Shift the exclusive end (the day after the last day), then step back one day. That gives Month(y, m).Shift(P1M) == Month(y, m + 1), the same as LocalDateTimeRange and PostgreSQL. 10.0.0 hasn't shipped, so this changes nothing anyone has received.

Done when

  • R31 and docs/ranges.md describe the new rule.
  • A test holds Month(y, m).Shift(P1M) == Month(next) and Quarter(...).Shift(P3M) == Quarter(next) for every month of a leap and a non-leap year, and an Expand case.
  • The test fails with the old rule restored.

Activity

  1. added this to the 10.0.0 milestone on Oct 18, 2026
  2. added
    bug
    silent
    area/ranges
    package/nodatime
    package/core
    severity/medium
    on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/rangesbugpackage/corepackage/nodatimeseverity/mediumsilent

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions