Skip to content

Commit fadc18d

Browse files
authored
subtle bug in the condition (dotnet#42633)
* subtle bug in the condition subtle bug in the condition used for checking if the store is open within the specified hours. Ensures that both conditions are checked logically (time must be both greater than or equal to the opening time and less than or equal to the closing time for the store to be considered open) * update output
1 parent 9ec74a3 commit fadc18d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

samples/snippets/csharp/VS_Snippets_CLR/conceptual.choosingdates/cs/datetimereplacement1.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public bool IsOpenAt(TimeSpan time)
3434
storeDelta = tz.GetAdjustmentRules()[tz.GetAdjustmentRules().Length - 1].DaylightDelta;
3535

3636
TimeSpan comparisonTime = time + (offset - tz.BaseUtcOffset).Negate() + (delta - storeDelta).Negate();
37-
return comparisonTime >= open & comparisonTime <= close;
37+
return comparisonTime >= open && comparisonTime <= close;
3838
}
3939
}
4040
}
@@ -66,7 +66,7 @@ public static void Main()
6666
// The example displays the following output:
6767
// Store is open now at 15:29:01.6129911: True
6868
// Store is open at 08:00:00: True
69-
// Store is open at 21:00:00: False
69+
// Store is open at 21:00:00: True
7070
// Store is open at 04:59:00: False
71-
// Store is open at 18:31:00: False
71+
// Store is open at 18:31:00: True
7272
// </Snippet2>

0 commit comments

Comments
 (0)