Repository navigation
Open
Description
| Environment | |
|---|---|
| PostgreSQL | 18.6 (postgres:18), session TimeZone Etc/UTC |
| .NET 10 | runtime 10.0.15, Npgsql.EntityFrameworkCore.PostgreSQL 10.0.4, EF Core 10.0.15, Npgsql 10.0.4 |
| .NET 11 | runtime 11.0.0, Npgsql.EntityFrameworkCore.PostgreSQL 11.0.0, EF Core 11.0.0, Npgsql 11.0.0 |
| Also | macOS arm64 |
Both lines print the same output. main at 9a76cd8 has the same code.
This issue used to bundle four BCL date/time members. TimeOnly.IsBetween moved to #4129 (fixed by #4127); at your request the other two are now #4148 and #4149.
date_part('second', …) includes the fraction, and ::int rounds it, so 59.999 seconds becomes 60. .NET's DateTime.Second is the whole seconds, 0 to 59.
| LINQ | Row | .NET | PostgreSQL | SQL |
|---|---|---|---|---|
r.Timestamp.Second |
23:59:59.999 | 59 | 60 | date_part('second', r."Timestamp" AT TIME ZONE 'UTC')::int |
Repro
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
await using var context = new TestContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.Rows.Add(new Row { Timestamp = new DateTime(2026, 2, 28, 23, 59, 59, 999, DateTimeKind.Utc) });
await context.SaveChangesAsync();
var row = await context.Rows.AsNoTracking().SingleAsync();
Console.WriteLine($"DateTime(23:59:59.999).Second: .NET {row.Timestamp.Second}, database {await context.Rows.Select(r => r.Timestamp.Second).SingleAsync()}");
public class TestContext : DbContext
{
public DbSet<Row> Rows => Set<Row>();
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(Environment.GetEnvironmentVariable("Test__Npgsql__DefaultConnection"))
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
}
public class Row
{
public int Id { get; set; }
public DateTime Timestamp { get; set; }
}Output, the same on both lines:
DateTime(23:59:59.999).Second: .NET 59, database 60
The translation is NpgsqlDateTimeMemberTranslator.cs#L132. Millisecond on the next line already floors (NpgsqlDateTimeMemberTranslator.cs#L134); floor(date_part('second', …))::int would match .NET.
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-]BCL date/time members: `.Second` rounds (up to 60), `TimeOnly.IsBetween` across midnight, `TimeOnly - TimeOnly`, lifted `DateTimeOffset.DateTime`[/-][+]BCL date/time members: `.Second` rounds (up to 60), `TimeOnly - TimeOnly`, lifted `DateTimeOffset.DateTime`[/+]roji commentedon Nov 17, 2026
Split the
TimeOnly.IsBetweenmidnight-spanning range bug into #4129, with #4127 linked as its fix. Updated this issue’s title to reflect the remaining scope.This issue remains open for the
.Secondrounding,TimeOnly - TimeOnlywraparound, and liftedDateTimeOffset.DateTimeproblems; the original report and repro are preserved above.Posted by copilot
Fix TimeOnly.IsBetween for midnight-spanning ranges (#4127)
[-]BCL date/time members: `.Second` rounds (up to 60), `TimeOnly - TimeOnly`, lifted `DateTimeOffset.DateTime`[/-][+]`DateTime.Second` rounds the fraction, so 23:59:59.999 gives 60[/+]