Skip to content

Commit 2f845f9

Browse files
Fix issue where macOS machines set to Morocco/Casablanca Timezone were one hour behind (UUM-87263)
1 parent d33523f commit 2f845f9

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

external/corefx-bugfix/src/Common/src/CoreLib/System/TimeZoneInfo.Unix.cs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,21 +1009,12 @@ private static void TZif_GenerateAdjustmentRule(ref int index, TimeSpan timeZone
10091009
// NOTE: index == dts.Length
10101010
DateTime startTransitionDate = dts[index - 1];
10111011

1012-
if (!string.IsNullOrEmpty(futureTransitionsPosixFormat))
1013-
{
1014-
AdjustmentRule r = TZif_CreateAdjustmentRuleForPosixFormat(futureTransitionsPosixFormat, startTransitionDate, timeZoneBaseUtcOffset);
1015-
1016-
if (r != null)
1017-
{
1018-
if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r))
1019-
{
1020-
NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r);
1021-
}
1022-
1023-
rulesList.Add(r);
1024-
}
1025-
}
1026-
else
1012+
// pulled in from this fix
1013+
// https://github.com/dotnet/runtime/pull/458/
1014+
AdjustmentRule r = !string.IsNullOrEmpty(futureTransitionsPosixFormat) ?
1015+
TZif_CreateAdjustmentRuleForPosixFormat(futureTransitionsPosixFormat, startTransitionDate, timeZoneBaseUtcOffset) :
1016+
null;
1017+
if (r == null)
10271018
{
10281019
// just use the last transition as the rule which will be used until the end of time
10291020

@@ -1032,22 +1023,22 @@ private static void TZif_GenerateAdjustmentRule(ref int index, TimeSpan timeZone
10321023
TimeSpan daylightDelta = transitionType.IsDst ? transitionOffset : TimeSpan.Zero;
10331024
TimeSpan baseUtcDelta = transitionType.IsDst ? TimeSpan.Zero : transitionOffset;
10341025

1035-
AdjustmentRule r = AdjustmentRule.CreateAdjustmentRule(
1026+
r = AdjustmentRule.CreateAdjustmentRule(
10361027
startTransitionDate,
10371028
DateTime.MaxValue,
10381029
daylightDelta,
1039-
default(TransitionTime),
1040-
default(TransitionTime),
1030+
default,
1031+
default,
10411032
baseUtcDelta,
10421033
noDaylightTransitions: true);
1034+
}
10431035

1044-
if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r))
1045-
{
1046-
NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r);
1047-
}
1048-
1049-
rulesList.Add(r);
1036+
if (!IsValidAdjustmentRuleOffest(timeZoneBaseUtcOffset, r))
1037+
{
1038+
NormalizeAdjustmentRuleOffset(timeZoneBaseUtcOffset, ref r);
10501039
}
1040+
1041+
rulesList.Add(r);
10511042
}
10521043

10531044
index++;
@@ -1141,15 +1132,20 @@ private static AdjustmentRule TZif_CreateAdjustmentRuleForPosixFormat(string pos
11411132
daylightSavingsTimeSpan = TZif_CalculateTransitionOffsetFromBase(daylightSavingsTimeSpan, baseOffset);
11421133
}
11431134

1144-
TransitionTime dstStart = TZif_CreateTransitionTimeFromPosixRule(start, startTime);
1145-
TransitionTime dstEnd = TZif_CreateTransitionTimeFromPosixRule(end, endTime);
1135+
TransitionTime? dstStart = TZif_CreateTransitionTimeFromPosixRule(start, startTime);
1136+
TransitionTime? dstEnd = TZif_CreateTransitionTimeFromPosixRule(end, endTime);
1137+
1138+
if (dstStart == null || dstEnd == null)
1139+
{
1140+
return null;
1141+
}
11461142

11471143
return AdjustmentRule.CreateAdjustmentRule(
11481144
startTransitionDate,
11491145
DateTime.MaxValue,
11501146
daylightSavingsTimeSpan,
1151-
dstStart,
1152-
dstEnd,
1147+
dstStart.GetValueOrDefault(),
1148+
dstEnd.GetValueOrDefault(),
11531149
baseOffset,
11541150
noDaylightTransitions: false);
11551151
}
@@ -1240,11 +1236,11 @@ private static DateTime ParseTimeOfDay(string time)
12401236
return timeOfDay;
12411237
}
12421238

1243-
private static TransitionTime TZif_CreateTransitionTimeFromPosixRule(string date, string time)
1239+
private static TransitionTime? TZif_CreateTransitionTimeFromPosixRule(string date, string time)
12441240
{
12451241
if (string.IsNullOrEmpty(date))
12461242
{
1247-
return default(TransitionTime);
1243+
return null;
12481244
}
12491245

12501246
if (date[0] == 'M')
@@ -1290,7 +1286,8 @@ private static TransitionTime TZif_CreateTransitionTimeFromPosixRule(string date
12901286
//
12911287
// If we need to support n format, we'll have to have a floating adjustment rule support this case.
12921288

1293-
throw new InvalidTimeZoneException(SR.InvalidTimeZone_NJulianDayNotSupported);
1289+
// Since we can't support this rule, return null to indicate to skip the POSIX rule.
1290+
return null;
12941291
}
12951292

12961293
// Julian day

0 commit comments

Comments
 (0)