From 685043bb1c02691b849a8df1ae231b8e23658ca3 Mon Sep 17 00:00:00 2001 From: Kyle Kukshtel Date: Fri, 20 Dec 2024 17:35:44 +0100 Subject: [PATCH] fixes issue where morocco timezone was one hour behind source from this fix from coreclr https://github.com/dotnet/runtime/pull/458/ --- .../src/CoreLib/System/TimeZoneInfo.Unix.cs | 59 +++++++++---------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/external/corefx-bugfix/src/Common/src/CoreLib/System/TimeZoneInfo.Unix.cs b/external/corefx-bugfix/src/Common/src/CoreLib/System/TimeZoneInfo.Unix.cs index 789d4803ac2c..48851ff049e0 100644 --- a/external/corefx-bugfix/src/Common/src/CoreLib/System/TimeZoneInfo.Unix.cs +++ b/external/corefx-bugfix/src/Common/src/CoreLib/System/TimeZoneInfo.Unix.cs @@ -1009,21 +1009,12 @@ private static void TZif_GenerateAdjustmentRule(ref int index, TimeSpan timeZone // NOTE: index == dts.Length DateTime startTransitionDate = dts[index - 1]; - if (!string.IsNullOrEmpty(futureTransitionsPosixFormat)) - { - AdjustmentRule r = TZif_CreateAdjustmentRuleForPosixFormat(futureTransitionsPosixFormat, startTransitionDate, timeZoneBaseUtcOffset); - - if (r != null) - { - if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r)) - { - NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r); - } - - rulesList.Add(r); - } - } - else + // pulled in from this fix + // https://github.com/dotnet/runtime/pull/458/ + AdjustmentRule? r = !string.IsNullOrEmpty(futureTransitionsPosixFormat) ? + TZif_CreateAdjustmentRuleForPosixFormat(futureTransitionsPosixFormat, startTransitionDate, timeZoneBaseUtcOffset) : + null; + if (r == null) { // just use the last transition as the rule which will be used until the end of time @@ -1032,22 +1023,22 @@ private static void TZif_GenerateAdjustmentRule(ref int index, TimeSpan timeZone TimeSpan daylightDelta = transitionType.IsDst ? transitionOffset : TimeSpan.Zero; TimeSpan baseUtcDelta = transitionType.IsDst ? TimeSpan.Zero : transitionOffset; - AdjustmentRule r = AdjustmentRule.CreateAdjustmentRule( + r = AdjustmentRule.CreateAdjustmentRule( startTransitionDate, DateTime.MaxValue, daylightDelta, - default(TransitionTime), - default(TransitionTime), + default, + default, baseUtcDelta, noDaylightTransitions: true); + } - if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r)) - { - NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r); - } - - rulesList.Add(r); + if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r)) + { + NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r); } + + rulesList.Add(r); } index++; @@ -1141,15 +1132,20 @@ private static AdjustmentRule TZif_CreateAdjustmentRuleForPosixFormat(string pos daylightSavingsTimeSpan = TZif_CalculateTransitionOffsetFromBase(daylightSavingsTimeSpan, baseOffset); } - TransitionTime dstStart = TZif_CreateTransitionTimeFromPosixRule(start, startTime); - TransitionTime dstEnd = TZif_CreateTransitionTimeFromPosixRule(end, endTime); + TransitionTime? dstStart = TZif_CreateTransitionTimeFromPosixRule(start, startTime); + TransitionTime? dstEnd = TZif_CreateTransitionTimeFromPosixRule(end, endTime); + + if (dstStart == null || dstEnd == null) + { + return null; + } return AdjustmentRule.CreateAdjustmentRule( startTransitionDate, DateTime.MaxValue, daylightSavingsTimeSpan, - dstStart, - dstEnd, + dstStart.GetValueOrDefault(), + dstEnd.GetValueOrDefault(), baseOffset, noDaylightTransitions: false); } @@ -1240,11 +1236,11 @@ private static DateTime ParseTimeOfDay(string time) return timeOfDay; } - private static TransitionTime TZif_CreateTransitionTimeFromPosixRule(string date, string time) + private static TransitionTime? TZif_CreateTransitionTimeFromPosixRule(string date, string time) { if (string.IsNullOrEmpty(date)) { - return default(TransitionTime); + return null; } if (date[0] == 'M') @@ -1290,7 +1286,8 @@ private static TransitionTime TZif_CreateTransitionTimeFromPosixRule(string date // // If we need to support n format, we'll have to have a floating adjustment rule support this case. - throw new InvalidTimeZoneException(SR.InvalidTimeZone_NJulianDayNotSupported); + // Since we can't support this rule, return null to indicate to skip the POSIX rule. + return null; } // Julian day