Skip to content

feat: translate the DateRange calendar factories over a column (10.x, port of #191) - #449

Merged
CaffeinatedCoder merged 1 commit into
release/10.xfrom
feat/448-translate-calendar-factories-10.x
Oct 25, 2026
Merged

CaffeinatedCoder merged 1 commit into
release/10.xfrom
feat/448-translate-calendar-factories-10.x

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #448

Port of #191 (PR #447, merged into main as 7503c18) to release/10.x, for 10.3.0 (#408). This lands only on this branch, so #448 gets closed by hand after the merge.

Problem

On this line, DateRange.Month, Quarter, Year and IsoWeek fail translation in a Where when they read a column. A query can't filter or order by DateRange.Month(b.Day).

Change

  • f3ecbed: cherry-pick of 879c82a (-x):
    • The calendar arm in ValueRangesMethodCallTranslator: daterange(first, last, '[]'), with memory's first and last periods as constants. The integer forms use make_date, guarded for the year and the ISO week. Every argument memory rejects raises an error.
    • CalendarFactoryTranslationTests and CalendarFactoryParityTests, with its seed. CalendarFactoryExtremesTests in the infinity-disabled project. NodaCalendarFactoryClientSideTests.
    • The client-only tests moved to the NodaTime forms, which stay in memory.
    • translation-support.json, claims E46 and E76, docs/efcore.md#what-runs-where, docs/ranges.md and the EF Core README.
  • The changelog rows landed under [10.3.0] ### Added, after the Clamp row from 10.x: translate Clamp on Int32Range, Int64Range and DecimalRange (port of #406) #441, in both changelogs.
  • The only conflict was DeclaredNullabilityTests, which isn't on this line. Its hunk is dropped, and so is its entry in claim E76's heldBy. The parity test still checks that the filters and the projection agree.

Tests

Run on release/10.x with SDK 10.0.402 and EF Core 10.0.0:

  • Suites: conventions 420, EF translation 336, NodaTime EF translation 102. Both integration projects on PostgreSQL 16 and 18: 307 and 5 each, including CalendarFactoryParityTests, CalendarFactoryExtremesTests and TranslationSupportProbeTests. All passed.
  • Seed: dotnet run tools/oracles.cs seeds calendar reports CAUGHT.
  • Calendar arm removed: the 4 translation tests and the 3 parity tests fail, and all 35 parity calls are "Untranslated".
  • Newest patch: the EF Core 10.0.13 leg runs in CI, since local float restores fail intermittently on this machine (test: map each translator operand from its declared type, and sweep for it, on 10.x (port of #295, #433) #435).

🤖 Generated with Claude Code

DateRange.Month, Quarter, Year and IsoWeek failed translation in a Where
when their argument was a column. They now run as SQL with memory's
answers:

  daterange(<first day>, <last day>, '[]')

The first and last periods of DateOnly are constants taken from memory's
own factory and written through the date mapping, so they are -infinity
and infinity as Npgsql binds DateOnly.MinValue and MaxValue (the days
themselves with DisableDateTimeInfinityConversions). A date column at or
past them takes them too, so date_trunc never sees an infinity. Otherwise
date_trunc(unit, d::timestamp) and that plus '<n> <unit> -1 day'.

Measured on PostgreSQL 16 and 18 first (#191): to_date(..., 'IYYY-IW')
rolls week 53 of a 52-week year over, make_date accepts the years 10000
and -1, and the proposed [) form over date_trunc(infinity) is empty. So
the integer forms use make_date with a guard for the year, IsoWeek counts
from January 4 and checks the week against date_part('week', Dec 28),
and every argument memory rejects raises: a message cast to the type it
stands in for, which always holds an argument, since PostgreSQL folds a
constant cast while planning, even in a CASE arm no row reaches.

LocalDateRange and YearMonthRange stay in memory: a LocalDate at
-infinity (-9998-01-01) and the years before 4713 BC have no PostgreSQL
date, so the server would fail where memory answers.

CalendarFactoryParityTests holds every condition on #408's parity list;
CalendarFactoryExtremesTests the extremes with the infinity conversions
off. translation-support.json classifies DateRange server, and the docs
move the row.

Port to release/10.x (#448): DeclaredNullabilityTests isn't on this line,
so its hunk and its entry in claim E76's heldBy drop out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 879c82a)
@CaffeinatedCoder CaffeinatedCoder added this to the 10.3.0 milestone Oct 25, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request area/ranges Range unions, variants and the shape engines package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime labels Oct 25, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 684216b into release/10.x Oct 25, 2026
10 of 12 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/448-translate-calendar-factories-10.x branch October 25, 2026 18:07
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 enhancement New feature or request package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant