diff --git a/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx b/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx
index f1a5053c8cbb..37b49a1cd998 100644
--- a/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx
+++ b/src/coreclr/src/System.Private.CoreLib/Resources/Strings.resx
@@ -2644,9 +2644,6 @@
Invalid Julian day in POSIX strings.
-
- Julian n day in POSIX strings is not supported.
-
There are no ttinfo structures in the tzfile. At least one ttinfo structure is required in order to construct a TimeZoneInfo object.
diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs
index 6d18ec47ff2d..5b5b795735f0 100644
--- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs
@@ -981,21 +981,11 @@ internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool
// 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
@@ -1004,22 +994,22 @@ internal static TimeSpan GetDateTimeNowUtcOffsetFromUtc(DateTime time, out bool
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++;
@@ -1111,15 +1101,20 @@ private static TZifType TZif_GetEarlyDateTransitionType(TZifType[] transitionTyp
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);
}
@@ -1210,11 +1205,11 @@ private static DateTime ParseTimeOfDay(ReadOnlySpan time)
return timeOfDay;
}
- private static TransitionTime TZif_CreateTransitionTimeFromPosixRule(ReadOnlySpan date, ReadOnlySpan time)
+ private static TransitionTime? TZif_CreateTransitionTimeFromPosixRule(ReadOnlySpan date, ReadOnlySpan time)
{
if (date.IsEmpty)
{
- return default;
+ return null;
}
if (date[0] == 'M')
@@ -1260,7 +1255,8 @@ private static TransitionTime TZif_CreateTransitionTimeFromPosixRule(ReadOnlySpa
//
// 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