From af746cda24c3a43d49f640b3f6c69235f0aa9a06 Mon Sep 17 00:00:00 2001 From: Josh Peterson Date: Fri, 23 Aug 2019 09:33:04 -0400 Subject: [PATCH] Handle locales with the same daylight savings time start and end If the first and second transition DateTime objects are the same, `ValidateAdjustmentRule` will throw an exception. I'm unsure why these would be the same, but we do see that occur for some locales. In that case, just exit early. This change corrects Unity case 1160695. --- mcs/class/corlib/System/TimeZoneInfo.Unity.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mcs/class/corlib/System/TimeZoneInfo.Unity.cs b/mcs/class/corlib/System/TimeZoneInfo.Unity.cs index bc79e4139930..d724f464976f 100644 --- a/mcs/class/corlib/System/TimeZoneInfo.Unity.cs +++ b/mcs/class/corlib/System/TimeZoneInfo.Unity.cs @@ -54,6 +54,12 @@ static List CreateAdjustmentRule (int year, out Int64[] data, ou if(daylightNameCurrentYear != names[(int)TimeZoneNames.DaylightNameIdx]) return rulesForYear; + // If the first and second transition DateTime objects are the same, ValidateAdjustmentRule will throw + // an exception. I'm unsure why these would be the same, but we do see that occur for some locales. + // In that case, just exit early. + if (firstTransition.Equals(secondTransition)) + return rulesForYear; + var beginningOfYear = new DateTime (year, 1, 1, 0, 0, 0, 0); var endOfYearDay = new DateTime (year, 12, DateTime.DaysInMonth (year, 12)); var endOfYearMaxTimeout = new DateTime (year, 12, DateTime.DaysInMonth(year, 12), 23, 59, 59, 999);