Skip to content

Normalize DateTimeOffset values to UTC before EF Core/Npgsql query parameters #2

Description

@ai-iskuzhin

Npgsql requires DateTimeOffset values written or compared against timestamp with time zone to have offset +00:00.

If an RSQL filter contains an ISO date-time with a non-zero offset, for example:

GET /api/v1/acts?filter=date>=2026-05-15T10:30:00+05:00

EF/Npgsql can throw:

Cannot write DateTimeOffset with Offset=05:00:00 to PostgreSQL type 'timestamp with time zone', only offset 0 (UTC) is supported.

Expected behavior:

The parser/binder should either normalize parsed DateTimeOffset constants to UTC before building the LINQ expression:

value.ToUniversalTime()

or expose a hook/options callback that lets consumers normalize parsed literal values by target CLR type before expression generation.

Why this matters:

For API clients, ISO date-times with offsets are valid and useful. The backend stores everything in UTC, but query filters can still pass non-UTC DateTimeOffset constants into generated EF expressions unless the parser layer normalizes them.

Environment:

  • RsqlParserNet: 1.0.0
  • RsqlParserNet.AspNetCore: 1.0.0
  • RsqlParserNet.EntityFrameworkCore: 1.0.0
  • EF Core: 10.0.8
  • Npgsql.EntityFrameworkCore.PostgreSQL: 10.0.1
  • .NET: 10

Suggested API option:

options.NormalizeValue = (value, targetType) =>
{
    if (value is DateTimeOffset dto)
    {
        return dto.ToUniversalTime();
    }

    return value;
};

Or a built-in option:

options.NormalizeDateTimeOffsetsToUtc = true;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions