Repository navigation
feat: calendar factories (Month, Quarter, Year, IsoWeek) for the date ranges - #190
Merged
Merged
Conversation
…ange DateRange.Month, Quarter, Year and IsoWeek build the calendar ranges people build by hand, by number or from any day inside the period; LocalDateRange gets the same, YearMonthRange gets Quarter and Year. Weeks are ISO 8601 only: Monday to Sunday, numbered by ISO week-year, never the current culture's first day of the week. Each returns the union type, like CreateFinite, so the whole algebra applies without a cast. DateRange.IsoWeek(weekYear, week) checks the week against the week-year's length: ISOWeek.ToDateTime reads week 53 of a 52-week year as week 1 of the next, silently. CalendarRangeParityTests holds both packages against .NET's ISOWeek and NodaTime's WeekYearRules.Iso for every day of 1999-2031 and both domain ends, under five current cultures; two seeds prove it. Closes #48 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 18, 2026
# Conflicts: # CHANGELOG.md # docs/efcore.md # src/CodoMetis.ValueRanges.NodaTime/CHANGELOG.md # src/CodoMetis.ValueRanges/CHANGELOG.md # test/CodoMetis.ValueRanges.EFCore.PostgreSQL.IntegrationTests/ClientSideOnlyProjectionTests.cs # test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/ClientSideOnlyTranslationTests.cs # test/oracles/claims.json # test/oracles/clone-waivers.json # test/oracles/oracles.json
# Conflicts: # test/oracles/claims.json
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 #48
Problem
A month, a quarter, a year or a week was built by hand with
CreateFiniteand the right last day. That is easy to get wrong in February, at a quarter's end, and for weeks, where the first day and the numbering depend on a convention. The names and the week rule are hard to change later, and 10.0.0 is the LTS line, so they had to be settled before shipping.Change
DateRangeMonth(int year, int month),Month(DateOnly),Quarter(int year, int quarter),Quarter(DateOnly),Year(int year),Year(DateOnly),IsoWeek(int weekYear, int week),IsoWeek(DateOnly)LocalDateRangeLocalDateYearMonthRangeQuarter(int, int),Quarter(YearMonth),Year(int),Year(YearMonth)YearMonthRangehas noMonth(a one-month range isCreateFinite(m, m)) and noIsoWeek(a week does not align to months).Naming rationale (permanent on the LTS line)
DateRange.Month(2026, 10), notCreateMonthorForMonth. The call reads as the value it returns. The noun can't be mistaken for a shape factory:CreateFinite,CreateUnboundedStartandCreateUnboundedEndname a shape, and these name a calendar period. That matches .NET's own value factories (TimeSpan.FromDays, NodaTime'sPeriod.FromMonths) and the issue's sketch. No range type has an instance member of these names, and none can get one later without a clash the compiler reports.IsoWeek, notWeek. The rule is part of the name, so every call site states it, and nobody expects the culture's week. It also follows .NET'sSystem.Globalization.ISOWeek. A culture-dependent week will never be added, by the decision on this issue. If one ever were,Weekwould still be free, but nobody would be misled byIsoWeekmeanwhile.weekYear, notyear, for the week's year. Near January 1 the ISO week-year differs from the calendar year:IsoWeek(2026, 53)holds 2027-01-01. NodaTime's own name (WeekYearRules,GetWeekYear) says that, where .NET'sISOWeekcalls ityear.MonthOf(date)name would double the surface for no gain in clarity.DateRange), not theFinitevariant. I triedFinitefirst, for.Startand.Endwithout a pattern match. It made theTRangehalf of the algebra (Merge,Except,IsAdjacentTo,Union,Gap) uncallable without a cast, because those extensions needTRange : IRangeFactory<TRange, T>, which a variant is not. Same return type asCreateFinite.Week rule
ISO 8601 only, as decided: Monday to Sunday, and week 1 holds the year's first Thursday. The BCL side uses
System.Globalization.ISOWeekand day arithmetic, and the NodaTime side usesWeekYearRules.Iso. The current culture'sFirstDayOfWeekand calendar are never read. #100 (Split) uses the same rule.Finding
ISOWeek.ToDateTime(2027, 53, Monday)does not throw. It returns 2028-01-03, the Monday of week 1 of 2028, because .NET checksweek <= 53rather than against the week-year. SoIsoWeek(2027, 53)would have answered silently with the wrong week.DateRange.IsoWeeknow checksISOWeek.GetWeeksInYearand throwsArgumentOutOfRangeException, as NodaTime does. The revert is kept as the seediso-week-past-the-last-wraps.patch.EF Core
Called with values the query does not read, a factory is evaluated in memory and inlined as one
daterangeconstant. Sob.Period.Overlaps(DateRange.Month(2026, 10))runs asb."Period" && '[2026-10-01,2026-10-31]'::daterange. Called with a column, it fails translation in aWhereand runs in memory in aSelect. That is listed indocs/efcore.md#what-runs-where, and its intro now reads "almost always because PostgreSQL has no operator". Translating the column form throughdate_truncandmake_dateis a follow-up (#191).Also
The calendar block sits beside
Values()rather than afterCreateFinite. Inserted afterCreateFinite, it shifted the context of the existing seeddaterange-reports-continuous.patch, which then failedEverySeed_AppliesToTheCurrentTree.Docs:
docs/ranges.md("Create a month, a quarter, a year or a week"), the efcore row, package READMEs, changelogs under 10.0.0. Claims R32–R34 and E46. 13 clone-sweep waivers for the members only the date ranges have.Tests
CalendarRangeParityTests(conventions, differential, registered). It checks every day from 1999-12-01 to 2031-01-31 plus 14 days at each end of the domain, under the invariant culture,en-US,fa-IR,de-DEandar-EG. Each day is checked against the definitions (the period holds the day, the week runs Monday to Sunday) and against .NET'sISOWeeknumbering. TheLocalDateRangeandYearMonthRangeresults must matchDateRange's. Months and quarters must partition their year, consecutive ISO weeks must be adjacent across week-years, and week 0 or week n+1 must throw in both packages.dotnet run tools/oracles.cs seeds iso-week):iso-week-reads-the-culture.patch(the week starts on the culture's first day) andiso-week-past-the-last-wraps.patch(the finding above).CalendarRangeTests,NodaTimeCalendarRangeTests: documented examples, argument checks, domain edges, and a JulianLocalDateread as its ISO day.InlineRangeConstantTests(the constant SQL),ClientSideOnlyTranslationTests(a column argument fails inWhere), andClientSideOnlyProjectionTests(integration: a column argument inSelect, and the constant form inWhere, against PostgreSQL).dotnet test: unit 1030, NodaTime 200, EF translation 254 + 81, conventions 326, ASP.NET Core 84, all green.🤖 Generated with Claude Code