-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix TimeZoneInfo to handle Yukon zone #43550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,40 @@ public static void LibyaTimeZone() | |
| Assert.True(libyaLocalTime.Equals(expectResult), string.Format("Expected {0} and got {1}", expectResult, libyaLocalTime)); | ||
| } | ||
|
|
||
| [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsWindows))] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need to be Windows specific? Wondering if it can be written in a way that works on Linux when running on an ICU that contains data for the same time zone. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I restricted this to Windows only for multiple reasons, first Windows zone id |
||
| public static void TestYukunTZ() | ||
| { | ||
| try | ||
| { | ||
| TimeZoneInfo yukon = TimeZoneInfo.FindSystemTimeZoneById("Yukon Standard Time"); | ||
|
|
||
| // First, ensure we have the updated data | ||
| TimeZoneInfo.AdjustmentRule [] rules = yukon.GetAdjustmentRules(); | ||
| if (rules.Length <= 0 || rules[rules.Length - 1].DateStart.Year != 2021 || rules[rules.Length - 1].DateEnd.Year != 9999) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| TimeSpan minus7HoursSpan = new TimeSpan(-7, 0, 0); | ||
|
|
||
| DateTimeOffset midnight = new DateTimeOffset(2021, 1, 1, 0, 0, 0, 0, minus7HoursSpan); | ||
| DateTimeOffset beforeMidnight = new DateTimeOffset(2020, 12, 31, 23, 59, 59, 999, minus7HoursSpan); | ||
| DateTimeOffset before1AM = new DateTimeOffset(2021, 1, 1, 0, 59, 59, 999, minus7HoursSpan); | ||
| DateTimeOffset at1AM = new DateTimeOffset(2021, 1, 1, 1, 0, 0, 0, minus7HoursSpan); | ||
| DateTimeOffset midnight2022 = new DateTimeOffset(2022, 1, 1, 0, 0, 0, 0, minus7HoursSpan); | ||
|
|
||
| Assert.Equal(minus7HoursSpan, yukon.GetUtcOffset(midnight)); | ||
| Assert.Equal(minus7HoursSpan, yukon.GetUtcOffset(beforeMidnight)); | ||
| Assert.Equal(minus7HoursSpan, yukon.GetUtcOffset(before1AM)); | ||
| Assert.Equal(minus7HoursSpan, yukon.GetUtcOffset(at1AM)); | ||
| Assert.Equal(minus7HoursSpan, yukon.GetUtcOffset(midnight2022)); | ||
| } | ||
| catch (TimeZoneNotFoundException) | ||
| { | ||
| // Some Windows versions don't carry the complete TZ data. Ignore the tests on such versiosn. | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public static void RussianTimeZone() | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why this extra check was there in the first place / what it was trying to prevent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was done long ago to minimize the risk on the Full Framework and we didn't have any case breaking this. But now we got the case that broke it.