Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUM-87263 Fix issue where macOS machines set to Morocco/Casablanca timezone were one hour behind #2103

Open
wants to merge 1 commit into
base: unity-main
Choose a base branch
from
Open
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 @@ -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) ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have run into a problem with AdjustmentRule being nullable. As it is a reference type, you may not need to add the ?. Does the commit work without it?

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