Skip to content

Commit

Permalink
fixes issue where morocco timezone was one hour behind
Browse files Browse the repository at this point in the history
source from this fix from coreclr dotnet/runtime#458
  • Loading branch information
kkukshtel-unity committed Dec 20, 2024
1 parent f28663b commit 685043b
Showing 1 changed file with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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++;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 685043b

Please sign in to comment.