-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
This issue has been moved from a ticket on Developer Community.
Yukon Standard Time was recently added to the Windows time zone registry and is thus available to use in DotNet. However, we have discovered there are some issues as to its implementation.
Issue 1:
Starting in 2021, the TimeZoneInfo.AdjustmentRule for "Yukon Standard Time" uses an internal BaseUtcOffsetDelta TimeSpan property to adjust the base UTC Offset for Yukon Standard Time. Is there a reason this property is not public and exposed on the TimeZoneInfo.AdjustementRule class?
Otherwise trying to derive the UTC offset of the Yukon Standard Time time zone after Jan 1, 2021 leads to an invalid UTC offset (without using the TimeZoneInfo.GetUtcOffset method) as the BaseUtcOffsetDelta is not taken into account (as its not known). We are currently using reflection to get this property value, as otherwise its hidden with the internal property accessor. For reference, we are exporting the values in the TimeZoneInfo classes to JSON objects to use within a Javascript library (similar to TimeZoneInfo in C#) to do time zones calculations on the browser without making a roundtrip to the server.
Issue 2:
As well, The "Yukon Standard Time" TimeZoneInfo reports the incorrect UTC Offset for the dates between 2021-01-01T00:00:00.000-7:00 and 2021-01-01T00:59:59.999-7:00 (inclusive). Instead of returning -7:00, it returns -8:00.
Tracing through the TimeZoneInfo class code, this appears to be an issue where the previous year's TimeZoneInfo.AdjustmentRule is being used due to the BaseUtcOffsetDelta not being applied until later on (meaning it selects 2020 as the year instead of 2021). Additionally, various edge-cases checks against using the next or previous rule are not being triggered due to the rule being more than one year long. I'm not sure if this is an issue with the rule selection logic, edge case conditions, or the underlying Yukon time zone data itself.
This also appears to affect SQL Server's AT TIME ZONE function, which I assume is implemented in a similar manner.
C# test case that should fail, but passes:
var yukon = TimeZoneInfo.FindSystemTimeZoneById("Yukon Standard Time");
var beforeMidnight = new DateTimeOffset(2020, 12, 31, 23, 59, 59, 999, new TimeSpan(-7, 0, 0));
var midnight = new DateTimeOffset(2021, 1, 1, 0, 0, 0, 0, new TimeSpan(-7, 0, 0));
var before1AM = new DateTimeOffset(2021, 1, 1, 0, 59, 59, 999, new TimeSpan(-7, 0, 0));
var at1AM = new DateTimeOffset(2021, 1, 1, 1, 0, 0, 0, new TimeSpan(-7, 0, 0));
var midnight2022 = new DateTimeOffset(2022, 1, 1, 0, 0, 0, 0, new TimeSpan(-7, 0, 0));
Assert.AreEqual(new TimeSpan(-7, 0, 0), yukon. GetUtcOffset(beforeMidnight), "On date " + beforeMidnight.ToString());
Assert.AreEqual(new TimeSpan(-8, 0, 0), yukon. GetUtcOffset(midnight), "On date " + midnight. ToString()); // This assert should fail, but it doesn't as the wrong offset is returned
Assert.AreEqual(new TimeSpan(-8, 0, 0), yukon. GetUtcOffset(before1AM), "On date " + before1AM.ToString()); // This assert should fail, but it doesn't as the wrong offset is returned
Assert.AreEqual(new TimeSpan(-7, 0, 0), yukon. GetUtcOffset(at1AM), "On date " + at1AM.ToString());
Assert.AreEqual(new TimeSpan(-7, 0, 0), yukon. GetUtcOffset(midnight2022), "On date " + midnight2022. ToString());
Original Comments
Feedback Bot on 10/14/2020, 03:33 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Original Solutions
(no solutions)