Skip to content

DateTime.ToUniversalTime() returns wrong UTC for local times in the DST gap on .NET 11 (regression from .NET 10) #134846

Closed

Description

@Dona278

Description

On .NET 11 RC1, DateTime.ToUniversalTime() on a DateTimeKind.Local value that falls in the spring-forward gap (an invalid time) no longer subtracts the standard offset, as documented:

If the date and time instance value is an invalid time, this method simply subtracts the local time from the local time zone's UTC offset to return UTC.

It appears to add the offset instead. For W. Europe Standard Time (UTC+1, DST +2), 2026-03-29 02:30 local becomes 03:30Z instead of 01:30Z.

The result also disagrees with the rest of the runtime for the same value:

  • TimeZoneInfo.Local.GetUtcOffset(local) returns +01:00;
  • new DateTimeOffset(local).UtcDateTime returns 01:30Z.

It also breaks ordering: 02:30 local maps to 03:30Z, which is later than 03:00 local → 01:00Z.

Reproduction Steps

Run on a machine whose local time zone is W. Europe Standard Time (or Europe/Berlin, Europe/Rome, …):

foreach (var wallClock in new[]
{
    new DateTime(2026, 03, 29, 01, 59, 00),
    new DateTime(2026, 03, 29, 02, 00, 00), // invalid
    new DateTime(2026, 03, 29, 02, 30, 00), // invalid
    new DateTime(2026, 03, 29, 02, 59, 00), // invalid
    new DateTime(2026, 03, 29, 03, 00, 00),
})
{
    var local = DateTime.SpecifyKind(wallClock, DateTimeKind.Local);
    Console.WriteLine(
        $"{wallClock:HH:mm} invalid={TimeZoneInfo.Local.IsInvalidTime(local),-5} " +
        $"ToUniversalTime={local.ToUniversalTime():HH:mm}Z " +
        $"GetUtcOffset={TimeZoneInfo.Local.GetUtcOffset(local)} " +
        $"DateTimeOffset={new DateTimeOffset(local).UtcDateTime:HH:mm}Z");
}

Expected behavior

This is the .NET 10.0.12 output:

01:59 invalid=False ToUniversalTime=00:59Z GetUtcOffset=01:00:00 DateTimeOffset=00:59Z
02:00 invalid=True  ToUniversalTime=01:00Z GetUtcOffset=01:00:00 DateTimeOffset=01:00Z
02:30 invalid=True  ToUniversalTime=01:30Z GetUtcOffset=01:00:00 DateTimeOffset=01:30Z
02:59 invalid=True  ToUniversalTime=01:59Z GetUtcOffset=01:00:00 DateTimeOffset=01:59Z
03:00 invalid=False ToUniversalTime=01:00Z GetUtcOffset=02:00:00 DateTimeOffset=01:00Z

Actual behavior

This is the .NET 11.0.0-rc.1.26425.128 output:

01:59 invalid=False ToUniversalTime=00:59Z GetUtcOffset=01:00:00 DateTimeOffset=00:59Z
02:00 invalid=True  ToUniversalTime=03:00Z GetUtcOffset=01:00:00 DateTimeOffset=01:00Z
02:30 invalid=True  ToUniversalTime=03:30Z GetUtcOffset=01:00:00 DateTimeOffset=01:30Z
02:59 invalid=True  ToUniversalTime=03:59Z GetUtcOffset=01:00:00 DateTimeOffset=01:59Z
03:00 invalid=False ToUniversalTime=01:00Z GetUtcOffset=02:00:00 DateTimeOffset=01:00Z

Only the invalid times are affected, and the error is always +2h. That is consistent with the offset being added instead of subtracted (02:30 + 01:00 = 03:30).

Regression?

Yes. It works on .NET 10.0.12 and fails on .NET 11.0.0-rc.1.26425.128. It is possibly related to the time zone rewrite in #119662. The corner-case regressions #126940 / #127009 came from the same change.

Known Workarounds

Compute the UTC value from TimeZoneInfo.Local.GetUtcOffset(local), which behaves the same on both versions, or use new DateTimeOffset(local).UtcDateTime.

Configuration

  • .NET 11.0.0-rc.1.26425.128 (compared with .NET 10.0.12)
  • Windows 11 Pro 10.0.26200, x64
  • Local time zone: W. Europe Standard Time

Other information

  • TimeZoneInfo.ConvertTimeToUtc(local) throws ArgumentException for these values on both versions, as expected. So the difference seems limited to the NoThrowOnInvalidTime path used by ToUniversalTime().
  • Not tested on Linux/macOS or with a time zone behind UTC.

Activity

  1. added
    untriaged
    on Sep 29, 2026
  2. dotnet-policy-service commented on Sep 29, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-datetime
    See info in area-owners.md if you want to be subscribed.

  3. removed
    untriaged
    on Sep 29, 2026
  4. self-assigned this
    on Sep 29, 2026
  5. added this to the 11.0.0 milestone on Sep 29, 2026
  6. tarekgh commented on Sep 29, 2026

    @tarekgh
    Member

    Thanks @Dona278 for reporting it!

  7. jozkee commented on Sep 29, 2026

    @jozkee
    Member

    subtracts the local time from the local time zone's UTC offset to return UTC.

    isn't this sentence backwards? Shouldn't it be "subtracts the local time zone's UTC offset from the local time"?.

  8. tarekgh commented on Sep 29, 2026

    @tarekgh
    Member

    isn't this sentence backwards? Shouldn't it be "subtracts the local time zone's UTC offset from the local time"?.

    Technically you are right. Mostly I am seeing cases user interpret it correctly even when written this way. 😄

  9. locked and limited conversation to collaborators on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions