Skip to content

Commit

Permalink
Cast NodaTime DateInterval.End to date. Fixes #3015
Browse files Browse the repository at this point in the history
  • Loading branch information
haas-daniel committed Dec 12, 2023
1 parent 1f724d3 commit e685457
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,13 @@ SqlExpression Upper()

if (member == DateInterval_End)
{
return
_sqlExpressionFactory.Subtract(
var upperBound = _sqlExpressionFactory.Subtract(
Upper(),
_sqlExpressionFactory.Constant(Period.FromDays(1), _periodTypeMapping));

// PostgreSQL creates a result of type 'timestamp without time zone' when subtracting periods from dates.
// So we need to cast it to date explicitly.
return _sqlExpressionFactory.Convert(upperBound, typeof(LocalDate), _typeMappingSource.FindMapping(typeof(LocalDate)));
}

if (member == DateInterval_Length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ await AssertQuery(
"""
SELECT n."Id", n."DateInterval", n."Duration", n."Instant", n."InstantRange", n."Interval", n."LocalDate", n."LocalDate2", n."LocalDateRange", n."LocalDateTime", n."LocalTime", n."Long", n."OffsetTime", n."Period", n."TimeZoneId", n."ZonedDateTime"
FROM "NodaTimeTypes" AS n
WHERE upper(n."DateInterval") - INTERVAL 'P1D' = DATE '2018-04-24'
WHERE CAST(upper(n."DateInterval") - INTERVAL 'P1D' AS date) = DATE '2018-04-24'
""");
}

Expand Down

0 comments on commit e685457

Please sign in to comment.