Skip to content

ZonedDateTime JSON writer produces values its reader cannot deserialize #4021

Closed

Description

@roji

Description

The NodaTime ZonedDateTime JSON reader cannot deserialize the writer's output for a value in a non-UTC zone. For example, a Europe/Berlin value in April serializes with +02, but deserialization throws NodaTime.Text.UnparsableValueException.

Minimal repro

Run this as a .NET 11 console application referencing src/EFCore.PG.NodaTime/EFCore.PG.NodaTime.csproj from this repository. No PostgreSQL server is required.

using System.Text;
using Microsoft.EntityFrameworkCore.Storage.Json;
using NodaTime;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;

var value = new LocalDateTime(2018, 4, 20, 10, 31, 33)
    .InZoneLeniently(DateTimeZoneProviders.Tzdb["Europe/Berlin"]);
var readerWriter = TimestampTzZonedDateTimeMapping.Default.JsonValueReaderWriter!;
var json = readerWriter.ToJsonString(value);
Console.WriteLine(json);

var reader = new Utf8JsonReaderManager(
    new JsonReaderData(Encoding.UTF8.GetBytes(json)), null);
reader.MoveNext();
Console.WriteLine(readerWriter.FromJson(ref reader, existingObject: null));

Actual behavior

The writer emits a JSON string containing 2018-04-20T10:31:33+02 (the plus sign is JSON-escaped as \u002B). Reading that string throws:

NodaTime.Text.UnparsableValueException:
The specified offset is invalid for the given date/time.
Value being parsed: '2018-04-20T10:31:33+02'.

Expected behavior

The JSON reader should deserialize the existing writer's output without throwing, preserving the stored local date/time, offset, and instant. Returning a fixed-offset zone is sufficient; this fix should not change the existing JSON representation.

Preserving the original named zone is a separate feature tracked in #4036 and is outside this issue's scope.

Cause

TimestampTzZonedDateTimeMapping uses a pattern containing the local date/time and offset. Parsing treats that text as a ZonedDateTime in the pattern's default UTC zone, so a nonzero offset can be rejected. Reading the stored offset directly avoids this failure without changing the writer.

Environment

Confirmed against main at d98928a7, using .NET SDK 11.0.100-rc.2.26504.105 and EF Core 11.0.0-rc.2.26504.105. Discovered while auditing date/time formatting for #3532; this is independent of BCE formatting.

Activity

  1. added theissue type on Oct 18, 2026
  2. self-assigned this
    on Oct 18, 2026
  3. added this to the 10.0.4 milestone on Oct 18, 2026
  4. added 3 commits that reference this issue on Oct 18, 2026
    92d483c
    bb449e9
    b038505
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions