TimeZoneInfo.CreateCustomTimeZone Not Obeying disableDaylightSavingTime Parameter

Open
#112,641 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
46/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp

Research direction

Start in src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs at CreateCustomTimeZone, then trace how its adjustmentRules are used by ConvertTimeFromUtc. Run the supplied reproduction on the affected runtime and verify that a custom zone created with disableDaylightSavingTime=true ignores daylight-saving adjustments while retaining the expected base offset.

Written by the indexing model from the issue text.

Description

area-System.DateTime
Description

When calling the TimeZoneInfo.CreateCustomTimeZone method overload that accepts the disableDaylightSavingTime parameter and then subsequently calling TimeZoneInfo.ConvertTimeFromUtc during a daylight savings timeframe it returns a DST adjusted time but shouldn't.

Reproduction Steps
TimeZoneInfo astTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Atlantic Standard Time");

TimeZoneInfo astDstDisabledTimeZone = TimeZoneInfo.CreateCustomTimeZone(
    astTimeZone.Id,
    astTimeZone.BaseUtcOffset,
    astTimeZone.DisplayName,
    astTimeZone.StandardName,
    astTimeZone.DaylightName,
    astTimeZone.GetAdjustmentRules(),
    true);

Console.WriteLine("AST with DST Enabled (UTC-3): " + TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse("4/1/2025 12:00:00"), astTimeZone));
Console.WriteLine("AST with DST Disabled (UTC-4): " + TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse("4/1/2025 12:00:00"), astDstDisabledTimeZone));
Expected behavior

AST with DST Enabled (UTC-3): 4/1/2025 9:00:00 AM
AST with DST Disabled (UTC-4): 4/1/2025 8:00:00 AM

Actual behavior

AST with DST Enabled (UTC-3): 4/1/2025 9:00:00 AM
AST with DST Disabled (UTC-4): 4/1/2025 9:00:00 AM

Regression?

When run with .Net Framework 4.7.2 it produces the expected output.

I also tested on .Net Core 3.1 and .Net 5 through .Net 9 and they all have the bug.

Known Workarounds

Pass null for the adjustmentRules parameter.

Configuration
  • Which version of .NET is the code running on? .Net 9
  • What OS and version, and what distro if applicable? Windows 11
  • What is the architecture (x64, x86, ARM, ARM64)? x64
  • Do you know whether it is specific to that configuration? I don't
Other information

Possibly in the CreateCustomTimeZone function. If DST is enabled and there are adjustment rules it clones them. However, if DST is disabled it just passes through the rules to the TimeZoneInfo constructor. Though maybe it should be discarding the adjustment rules in TimeZoneInfo constructor itself to cover more use cases.

I presume discarding of the rules is the itended implemention based on the documentation.

disableDaylightSavingTime Boolean
true to discard any daylight saving time-related information present in adjustmentRules with the new object; otherwise, false.

Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.