Description
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
.