Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Nothing was removed or renamed. Some calls answer differently, text that parsed
- Ranges: a record derived from a range type throws `InvalidOperationException` when it is constructed, so the five variants are the only ranges that can exist, as documented. C# gives every record a protected copy constructor, so `record Rogue(Int32Range Seed) : Int32Range(Seed)` compiled, and `IsEmpty()`, `Contains` and `Overlaps` answered the value `false` ([Pattern matching](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/ranges.md#why-the-discard-arm-must-throw)).
- EF Core: `Any` or `Count` with a predicate over an empty captured list of value sets, or of ranges beside a `Contains`, returns `false` or `0`, as in memory. It threw `InvalidOperationException` ("Empty collections are not supported as inline query roots") ([EF Core](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/efcore.md#match-a-column-against-a-list-of-sets)).
- Docs: an exclusive `infinity` or `-infinity` date bound excludes the date extreme, which stands for the infinity, so `[2026-01-01,infinity)` is `[2026-01-01,9999-12-30]` from a column and from the literal alike. Ask other tools to write an open end as absent or inclusive ([Domain width](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/architecture.md#domain-width-and-the-boundary)).
- Docs: a `YearMonthRange` column holding an exclusive `infinity)` or `(-infinity` throws `InvalidOperationException` when it loads, because the range covers part of a month. Ask other tools to write an absent or inclusive bound ([EF Core](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/efcore.md#rows-written-by-other-tools)).
- Docs: a temporal literal with more than six fraction digits keeps them in memory, while PostgreSQL reads the same text rounded to the microsecond and the EF Core package stores it truncated, so the three can be 1 µs apart ([Literals](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/serialization.md#dates-and-times-are-strict-iso-8601)).
- Literals: integer bounds and elements read PostgreSQL 16's `0x`, `0o` and `0b` prefixes and single underscores between digits, in `Int32Range`, `Int64Range`, their multiranges, `Int16Set`, `Int32Set`, `Int64Set` and the wrapper sets. `[0x1F,)` and `{1_000}` threw `FormatException` ([Literals](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/serialization.md#parse-a-literal)).
- Literals: every value set reads PostgreSQL's dimension decoration and drops it, so `[0:1]={1,2}`, which `array_out` prints for an array whose lower bound isn't 1, is `{1,2}`. A decoration that doesn't count the elements still throws `FormatException`. `{{}}` and `{{},{}}` read as `{}`, as PostgreSQL 17 and later read them (PostgreSQL 16 rejects them). Both threw `FormatException` ([Value sets](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/value-sets.md#parse-and-print-literals)).
Expand Down
6 changes: 6 additions & 0 deletions docs/efcore.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ If other tools write open-ended dates into your tables, have them write an absen
(`'[2026-01-01,infinity]'`, which loads as `[2026-01-01,9999-12-31]`). The same holds for
`LocalDateRange` ([Domain width](architecture.md#domain-width-and-the-boundary)).

A `YearMonthRange` column can't load the exclusive form at all. `[2026-01-01,infinity)` holds every
day up to 9999-12-30, which ends part-way through a month, so the query throws
`InvalidOperationException`, as it does for any range that covers part of a month. `(-infinity,x)`
fails the same way at its start. The absent and the inclusive forms work: `[2026-01-01,infinity]`
loads as `[2026-01,9999-12]`, and `daterange('2026-01-01', NULL)` as `[2026-01,)`.

The difference comes from reading rows normalized while leaving them as written. The alternatives
are rewriting other tools' rows on read, or not translating `Count` at all, and neither is worth it
for the common case. If you query `Count` on a table that other tools also write, put the data in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ covers all four packages, which share one version number and release together.

## [10.0.0] — 2026-10-17

No change in this package.
### Fixed

- Docs: a `YearMonthRange` column holding an exclusive `infinity)` or `(-infinity` throws `InvalidOperationException` when it loads, because the range covers part of a month. Ask other tools to write an absent or inclusive bound ([EF Core](https://github.com/CaffeinatedCoder/CodoMetis.ValueRanges/blob/main/docs/efcore.md#rows-written-by-other-tools)).

## [9.1.0] — 2026-10-17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,50 @@ public async Task YearMonthRange_AllShapes_RoundTripUnchanged()
}
}

/// <summary>
/// What a <see cref="YearMonthRange"/> column does with each way another tool can spell an open end
/// (#258). An absent bound and an inclusive infinity load as an unbounded side and as the last
/// month. An exclusive infinity does not: <c>[2026-01-01,infinity)</c> holds every day up to
/// 9999-12-30 (#117), which ends part-way through a month, so the load throws, as any range that
/// covers a partial month does. Reading it as the whole last month would change the row's value
/// when it is saved back, as <c>infinity]</c>.
/// </summary>
[TestMethod]
[DataRow(7191, "daterange('2026-01-01', NULL)", "[2026-01,)")]
[DataRow(7192, "daterange('2026-01-01', 'infinity', '[]')", "[2026-01,9999-12]")]
[DataRow(7193, "daterange('-infinity', '2026-02-01')", "[-9998-01,2026-01]")]
[DataRow(7194, "daterange('2026-01-01', 'infinity')", "not the last day of a month")]
[DataRow(7195, "daterange('-infinity', '2026-02-01', '()')", "not the first day of a month")]
public async Task YearMonthRange_AnOpenEndWrittenByAnotherTool_LoadsOrFailsLoudly(int id, string stored, string expected)
{
ContainerLifecycle.RequireDatabase();

await Seed(new Reservation { Id = id });
await using (var write = new IntegrationDbContext())
{
// The literal is this test's own constant, not input.
#pragma warning disable EF1002
await write.Database.ExecuteSqlRawAsync($"UPDATE \"Reservations\" SET \"BillingPeriod\" = {stored} WHERE \"Id\" = {id}");
#pragma warning restore EF1002
}

await using var context = new IntegrationDbContext();
string outcome;
try
{
outcome = (await context.Reservations.Where(r => r.Id == id).Select(r => r.BillingPeriod).SingleAsync()).ToString();
}
catch (Exception exception)
{
var root = exception;
while (root.InnerException is { } inner) root = inner;
Assert.IsInstanceOfType<InvalidOperationException>(root, exception.ToString());
outcome = root.Message;
}

StringAssert.Contains(outcome, expected, stored);
}

[TestMethod]
public async Task YearMonthRange_IsStoredAsMonthAlignedDateRange()
{
Expand Down
14 changes: 14 additions & 0 deletions test/oracles/claims.json
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,20 @@
"TimeAndYearMonthIntegrationTests"
]
},
{
"id": "E63-yearmonthrange-exclusive-infinity-fails-to-load",
"source": "docs/efcore.md#rows-written-by-other-tools",
"quote": "A `YearMonthRange` column can't load the exclusive form at all. `[2026-01-01,infinity)` holds every day up to 9999-12-30, which ends part-way through a month, so the query throws `InvalidOperationException`, as it does for any range that covers part of a month.",
"claim": "A YearMonthRange column holding daterange [x,infinity) or (-infinity,x) throws InvalidOperationException naming the partial month when loaded, while [x,infinity] loads as [x-month,9999-12], [-infinity,x) as [-9998-01, month before x] and an absent bound as an unbounded side.",
"oracle": "exception",
"surfaces": [
"YearMonthRange.CreateFinite",
"NodaTimeInteropExtensions.ToYearMonthRange"
],
"heldBy": [
"TimeAndYearMonthIntegrationTests"
]
},
{
"id": "J01-tostring-is-postgres-literal",
"source": "docs/serialization.md#print-a-range-as-a-literal",
Expand Down