Skip to content

Commit

Permalink
General infinity literals for DateTimeOffset min/max values (#2390)
Browse files Browse the repository at this point in the history
Fixes #2389

(cherry picked from commit e672715)
  • Loading branch information
roji committed Jun 1, 2022
1 parent d5eed85 commit 0f05a3b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ private string GenerateLiteralCore(object value)
};

case DateTimeOffset dateTimeOffset:
if (!NpgsqlTypeMappingSource.DisableDateTimeInfinityConversions)
{
if (dateTimeOffset == DateTimeOffset.MinValue)
{
return "-infinity";
}

if (dateTimeOffset == DateTimeOffset.MaxValue)
{
return "infinity";
}
}

return dateTimeOffset.ToString("yyyy-MM-dd HH:mm:ss.FFFFFFzzz", CultureInfo.InvariantCulture);

default:
Expand Down
8 changes: 8 additions & 0 deletions test/EFCore.PG.Tests/Storage/NpgsqlTypeMappingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ public void GenerateSqlLiteral_returns_timestamptz_infinity_literals()
Assert.Equal(
"TIMESTAMPTZ 'infinity'",
GetMapping("timestamptz").GenerateSqlLiteral(DateTime.MaxValue));

Assert.Equal(
"TIMESTAMPTZ '-infinity'",
GetMapping("timestamptz").GenerateSqlLiteral(DateTimeOffset.MinValue));

Assert.Equal(
"TIMESTAMPTZ 'infinity'",
GetMapping("timestamptz").GenerateSqlLiteral(DateTimeOffset.MaxValue));
}

[Fact]
Expand Down

0 comments on commit 0f05a3b

Please sign in to comment.