summaryrefslogtreecommitdiff
path: root/src/System.Private.CoreLib
diff options
context:
space:
mode:
authorEric Erhardt <eric.erhardt@microsoft.com>2020-01-14 12:35:16 -0600
committerAnirudh Agnihotry <anirudhagnihotry098@gmail.com>2020-01-14 10:35:15 -0800
commit2d996fc48fee36d8c95040c651f0625cd1d7c094 (patch)
tree9080c3101c5252003693ea7ef5f13f2a6bc099d6 /src/System.Private.CoreLib
parent593608385d854b2a16631d4df8cf3b43a86c84fe (diff)
downloadcoreclr-2d996fc48fee36d8c95040c651f0625cd1d7c094.tar.gz
coreclr-2d996fc48fee36d8c95040c651f0625cd1d7c094.tar.bz2
coreclr-2d996fc48fee36d8c95040c651f0625cd1d7c094.zip
Stop throwing exception in TimeZoneInfo POSIX parsing (#27969)
IsDaylightSavingTime_CasablancaMultiYearDaylightSavings fails on rhel.8 When parsing the tzdata POSIX string that contains an 'n' Julian date, we are currently throwing an exception, and then falling back to a TimeZoneInfo without DST enabled. However, this is a mistake because there are other DST transitions that were read from the tzdata file that are valid and usable. We shouldn't be throwing that information away. So instead, we now skip the POSIX string if we detect an unsupported 'n' Julian date, and just use the last transition as the AdjustmentRule for all the DateTimes in the future. This way we can still make DST determinations correctly for some DateTimes. Fix https://github.com/dotnet/corefx/issues/42192
Diffstat (limited to 'src/System.Private.CoreLib')
-rw-r--r--src/System.Private.CoreLib/Resources/Strings.resx3
-rw-r--r--src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs56
2 files changed, 26 insertions, 33 deletions
diff --git a/src/System.Private.CoreLib/Resources/Strings.resx b/src/System.Private.CoreLib/Resources/Strings.resx
index e8bc95242f..fdb6fdce19 100644
--- a/src/System.Private.CoreLib/Resources/Strings.resx
+++ b/src/System.Private.CoreLib/Resources/Strings.resx
@@ -2704,9 +2704,6 @@
<data name="InvalidTimeZone_InvalidJulianDay" xml:space="preserve">
<value>Invalid Julian day in POSIX strings.</value>
</data>
- <data name="InvalidTimeZone_NJulianDayNotSupported" xml:space="preserve">
- <value>Julian n day in POSIX strings is not supported.</value>
- </data>
<data name="InvalidTimeZone_NoTTInfoStructures" xml:space="preserve">
<value>There are no ttinfo structures in the tzfile. At least one ttinfo structure is required in order to construct a TimeZoneInfo object.</value>
</data>
diff --git a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
index b04ae348b7..708f98ed3e 100644
--- a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
+++ b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
@@ -985,21 +985,11 @@ namespace System
// 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);
- }
+ AdjustmentRule? r = !string.IsNullOrEmpty(futureTransitionsPosixFormat) ?
+ TZif_CreateAdjustmentRuleForPosixFormat(futureTransitionsPosixFormat, startTransitionDate, timeZoneBaseUtcOffset) :
+ null;
- rulesList.Add(r);
- }
- }
- else
+ if (r == null)
{
// just use the last transition as the rule which will be used until the end of time
@@ -1008,22 +998,22 @@ namespace System
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++;
@@ -1115,15 +1105,20 @@ namespace System
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);
}
@@ -1214,11 +1209,11 @@ namespace System
return timeOfDay;
}
- private static TransitionTime TZif_CreateTransitionTimeFromPosixRule(ReadOnlySpan<char> date, ReadOnlySpan<char> time)
+ private static TransitionTime? TZif_CreateTransitionTimeFromPosixRule(ReadOnlySpan<char> date, ReadOnlySpan<char> time)
{
if (date.IsEmpty)
{
- return default(TransitionTime);
+ return null;
}
if (date[0] == 'M')
@@ -1264,7 +1259,8 @@ namespace System
//
// 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