Skip to content
Open
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
20 changes: 14 additions & 6 deletions conceptual/EFCore.PG/mapping/nodatime.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ Starting with version 11.0, `EF.Functions.DateTrunc()` supports `LocalDateTime`,
.NET | SQL | Notes
-------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -----------
SystemClock.Instance.GetCurrentInstant() | [now()](https://www.postgresql.org/docs/current/functions-datetime.html) |
EF.Functions.DateTrunc("month", value) | [date_trunc('month', value)](https://www.postgresql.org/docs/current/functions-datetime.html) | Added in 11.0
EF.Functions.DateTrunc("month", instant, "Europe/Berlin") | [date_trunc('month', instant, 'Europe/Berlin')](https://www.postgresql.org/docs/current/functions-datetime.html) | Added in 11.0
EF.Functions.DateTrunc("month", value) | [date_trunc('month', value)](https://www.postgresql.org/docs/current/functions-datetime.html) | Added in 11.0
EF.Functions.DateTrunc("month", instant, "Europe/Berlin") | [date_trunc('month', instant, 'Europe/Berlin')](https://www.postgresql.org/docs/current/functions-datetime.html) | Added in 11.0
LocalDateTime.Date | [date_trunc('day', timestamp)](https://www.postgresql.org/docs/current/functions-datetime.html) |
LocalDateTime.Second (also LocalTime, ZonedDateTime) | [date_part('second', timestamp)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
LocalDateTime.Minute (also LocalTime, ZonedDateTime) | [date_part('minute', timestamp)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Expand All @@ -100,10 +100,10 @@ LocalDateTime.DayOfWeek (also LocalDate, ZonedDateTime)
LocalDateTime.DayOfYear (also LocalDate, ZonedDateTime) | [date_part('doy', timestamp)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
LocalDate.At(time) | [date + time](https://www.postgresql.org/docs/current/functions-datetime.html) | Added in 10.0
LocalDate.AtMidnight() | [date + '00:00:00'](https://www.postgresql.org/docs/current/functions-datetime.html) | Added in 10.0
Period.Seconds (also Duration) | [date_part('second', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Minutes (also Duration) | [date_part('minute', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Hours (also Duration) | [date_part('hour', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Days (also Duration) | [date_part('day', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Seconds | [date_part('second', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Minutes | [date_part('minute', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Hours | [date_part('hour', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Days | [date_part('day', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Months | [date_part('month', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.Years | [date_part('year', interval)::INT](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.FromSeconds | [make_interval(seconds => int)](https://www.postgresql.org/docs/current/functions-datetime.html) |
Expand All @@ -113,11 +113,17 @@ Period.FromDays
Period.FromWeeks | [make_interval(weeks => int)](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.FromMonths | [make_interval(months => int)](https://www.postgresql.org/docs/current/functions-datetime.html) |
Period.FromYears | [make_interval(years => int)](https://www.postgresql.org/docs/current/functions-datetime.html) |
Duration.Days | [date_part('day', justify_hours(interval))::INT](https://www.postgresql.org/docs/current/functions-datetime.html) | Changed in 11.0
Duration.Hours | [date_part('hour', justify_hours(interval))::INT](https://www.postgresql.org/docs/current/functions-datetime.html) | Changed in 11.0
Duration.Minutes | [date_part('minute', justify_hours(interval))::INT](https://www.postgresql.org/docs/current/functions-datetime.html) | Changed in 11.0
Duration.Seconds | [trunc(date_part('second', justify_hours(interval)))::INT](https://www.postgresql.org/docs/current/functions-datetime.html) | Changed in 11.0
Duration.Milliseconds | [trunc(date_part('millisecond', justify_hours(interval)))::INT % 1000](https://www.postgresql.org/docs/current/functions-datetime.html) | Added in 11.0
Duration.TotalMilliseconds | [date_part('epoch', interval) / 0.001](https://www.postgresql.org/docs/current/functions-datetime.html) |
Duration.TotalSeconds | [date_part('epoch', interval)](https://www.postgresql.org/docs/current/functions-datetime.html) |
Duration.TotalMinutes | [date_part('epoch', interval) / 60.0](https://www.postgresql.org/docs/current/functions-datetime.html) |
Duration.TotalDays | [date_part('epoch', interval) / 86400.0](https://www.postgresql.org/docs/current/functions-datetime.html) |
Duration.TotalHours | [date_part('epoch', interval) / 3600.0](https://www.postgresql.org/docs/current/functions-datetime.html) |
instant + duration (also ZonedDateTime, -) | [(instant AT TIME ZONE 'UTC' + interval) AT TIME ZONE 'UTC'](https://www.postgresql.org/docs/current/functions-datetime.html#OPERATORS-DATETIME-TABLE) | Computed in UTC since 11.0
ZonedDateTime.LocalDateTime | [timestamptz AT TIME ZONE 'UTC'](https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT) |
DateInterval.Length | [upper(daterange) - lower(daterange)](https://www.postgresql.org/docs/current/functions-range.html) |
DateInterval.Start | [lower(daterange)](https://www.postgresql.org/docs/current/functions-range.html) |
Expand All @@ -138,3 +144,5 @@ EF.Functions.Average(periods)
EF.Functions.Average(durations) | [avg(durations)](https://www.postgresql.org/docs/current/functions-aggregate.html#FUNCTIONS-AGGREGATE-TABLE) | See [Aggregate functions](translations.md#aggregate-functions).

In addition to the above, most arithmetic operators are also translated (e.g. LocalDate + Period).

Starting with version 11.0, adding or subtracting a `Duration` to an `Instant` or `ZonedDateTime` is computed in UTC. This is because PostgreSQL's `timestamp with time zone + interval` adds the interval's days in the session time zone, so that adding a day across a daylight saving time transition would add 23 or 25 hours, rather than the 24 hours added by NodaTime ([#4087](https://github.com/npgsql/efcore.pg/issues/4087)). Similarly, the `Duration` components (`Days`, `Hours`, etc.) are now truncated towards zero like in NodaTime, and are also correct for durations computed in SQL, whose day and time fields can have different signs ([#4088](https://github.com/npgsql/efcore.pg/issues/4088)).
Loading