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
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,13 @@ SqlExpression Upper()

if (member == DateInterval_End)
{
return
// PostgreSQL creates a result of type 'timestamp without time zone' when subtracting intervals from dates, so add a cast back
// to date.
return _sqlExpressionFactory.Convert(
_sqlExpressionFactory.Subtract(
Upper(),
_sqlExpressionFactory.Constant(Period.FromDays(1), _periodTypeMapping));
_sqlExpressionFactory.Constant(Period.FromDays(1), _periodTypeMapping)), 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,22 @@ 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'
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public async Task DateInterval_End_Select(bool async)
{
await AssertQuery(
async,
ss => ss.Set<NodaTimeTypes>().Select(t => t.DateInterval.End));

AssertSql(
"""
SELECT CAST(upper(n."DateInterval") - INTERVAL 'P1D' AS date)
FROM "NodaTimeTypes" AS n
""");
}

Expand Down