Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ internal static AdjustmentRule CreateAdjustmentRule(
internal bool IsStartDateMarkerForBeginningOfYear() =>
!NoDaylightTransitions &&
DaylightTransitionStart.Month == 1 && DaylightTransitionStart.Day == 1 &&
DaylightTransitionStart.TimeOfDay.TimeOfDay.Ticks < TimeSpan.TicksPerSecond && // < 12:00:01 AM
_dateStart.Year == _dateEnd.Year;
DaylightTransitionStart.TimeOfDay.TimeOfDay.Ticks < TimeSpan.TicksPerSecond; // < 12:00:01 AM

//
// When Windows sets the daylight transition end Jan 1st at 12:00 AM, it means the year ends with the daylight saving on.
Expand All @@ -129,8 +128,7 @@ internal bool IsStartDateMarkerForBeginningOfYear() =>
internal bool IsEndDateMarkerForEndOfYear() =>
!NoDaylightTransitions &&
DaylightTransitionEnd.Month == 1 && DaylightTransitionEnd.Day == 1 &&
DaylightTransitionEnd.TimeOfDay.TimeOfDay.Ticks < TimeSpan.TicksPerSecond && // < 12:00:01 AM
_dateStart.Year == _dateEnd.Year;
Copy link
Member

@stephentoub stephentoub Oct 17, 2020

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?

Copy link
Member Author

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.

DaylightTransitionEnd.TimeOfDay.TimeOfDay.Ticks < TimeSpan.TicksPerSecond; // < 12:00:01 AM

/// <summary>
/// Helper function that performs all of the validation checks for the factory methods and deserialization callback.
Expand Down
34 changes: 34 additions & 0 deletions src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

The 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 Yukon Standard Time cannot be used on Linux. Second the rules on Linux is very different than Windows. I added this test case mainly to test Windows edge cases. As I mentioned Windows has some limitation which cannot specify more than one transition per year while Linux data don't have this restriction. I am not expecting Yukon on Linux would be any different than any other zone which we already testing.

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()
{
Expand Down