Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion src/Npgsql.NodaTime/Internal/IntervalConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ async ValueTask<Interval> Read(bool async, PgReader reader, CancellationToken ca
: range.LowerBoundIsInclusive
? range.LowerBound
: range.LowerBound + Duration.Epsilon;
Instant? end = range.UpperBoundInfinite
// For ranges with element types with infinity values (datetime, date etc.) an
// inclusive lower/upper bound causes their -/+ infinity (respectively) to fall within the range.
// If those values are returned for such a range postgres will not mark the affected bound as infinite accordingly.
// This is documented in https://www.postgresql.org/docs/current/rangetypes.html#RANGETYPES-INFINITE
// As NodaTime uses an exclusive upper bound we must consider this case as being another form of infinity (null).
Instant? end = range.UpperBoundInfinite || (range.UpperBoundIsInclusive && range.UpperBound == Instant.MaxValue)
Comment thread
NinoFloris marked this conversation as resolved.
Outdated
? null
: range.UpperBoundIsInclusive
? range.UpperBound + Duration.Epsilon
Expand Down
20 changes: 20 additions & 0 deletions test/Npgsql.PluginTests/NodaTimeInfinityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,26 @@ public async Task Interval_convert_infinity()
}
}

[Test]
public async Task Inclusive_End_Range_Infinity_read()
{
await using var conn = await OpenConnectionAsync();
await using var cmd = new NpgsqlCommand(
"SELECT tstzrange('-infinity', 'infinity','[]') as val", conn);

await using var reader = await cmd.ExecuteReaderAsync();
await reader.ReadAsync();

if (Statics.DisableDateTimeInfinityConversions)
{
Assert.That(() => reader[0], Throws.Exception.TypeOf<InvalidCastException>());
}
else
{
Assert.That(reader[0], Is.EqualTo(new Interval(Instant.MinValue, null)));
}
}

protected override NpgsqlDataSource DataSource { get; }

public NodaTimeInfinityTests(bool disableDateTimeInfinityConversions)
Expand Down