Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d9820dd

Browse files
committed
Assert GetAdjustmentRuleForTime sets ruleIndex correctly.
1 parent a4b6694 commit d9820dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/mscorlib/src/System/TimeZoneInfo.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,10 @@ private TimeZoneInfo(SerializationInfo info, StreamingContext context)
10671067

10681068
private AdjustmentRule GetAdjustmentRuleForTime(DateTime dateTime, out int? ruleIndex)
10691069
{
1070-
return GetAdjustmentRuleForTime(dateTime, dateTimeisUtc: false, ruleIndex: out ruleIndex);
1070+
AdjustmentRule result = GetAdjustmentRuleForTime(dateTime, dateTimeisUtc: false, ruleIndex: out ruleIndex);
1071+
Debug.Assert(result == null || ruleIndex.HasValue, "If an AdjustmentRule was found, ruleIndex should also be set.");
1072+
1073+
return result;
10711074
}
10721075

10731076
private AdjustmentRule GetAdjustmentRuleForTime(DateTime dateTime, bool dateTimeisUtc, out int? ruleIndex)
@@ -1744,6 +1747,8 @@ internal static TimeSpan GetUtcOffsetFromUtc(DateTime time, TimeZoneInfo zone, o
17441747
else
17451748
{
17461749
rule = zone.GetAdjustmentRuleForTime(time, dateTimeisUtc: true, ruleIndex: out ruleIndex);
1750+
Debug.Assert(rule == null || ruleIndex.HasValue,
1751+
"If GetAdjustmentRuleForTime returned an AdjustmentRule, ruleIndex should also be set.");
17471752

17481753
// As we get the associated rule using the adjusted targetTime, we should use the adjusted year (targetTime.Year) too as after adding the baseOffset,
17491754
// sometimes the year value can change if the input datetime was very close to the beginning or the end of the year. Examples of such cases:

0 commit comments

Comments
 (0)