From fadc18d0f8aae33f9e7c6ed4dc50a877a5233a2c Mon Sep 17 00:00:00 2001 From: Stanislav Hut <99662137+stashut@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:17:16 +0300 Subject: [PATCH] subtle bug in the condition (#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 --- .../conceptual.choosingdates/cs/datetimereplacement1.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/snippets/csharp/VS_Snippets_CLR/conceptual.choosingdates/cs/datetimereplacement1.cs b/samples/snippets/csharp/VS_Snippets_CLR/conceptual.choosingdates/cs/datetimereplacement1.cs index a909c3e5e643c..2c9c0e1c618c1 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/conceptual.choosingdates/cs/datetimereplacement1.cs +++ b/samples/snippets/csharp/VS_Snippets_CLR/conceptual.choosingdates/cs/datetimereplacement1.cs @@ -34,7 +34,7 @@ public bool IsOpenAt(TimeSpan time) storeDelta = tz.GetAdjustmentRules()[tz.GetAdjustmentRules().Length - 1].DaylightDelta; TimeSpan comparisonTime = time + (offset - tz.BaseUtcOffset).Negate() + (delta - storeDelta).Negate(); - return comparisonTime >= open & comparisonTime <= close; + return comparisonTime >= open && comparisonTime <= close; } } } @@ -66,7 +66,7 @@ public static void Main() // The example displays the following output: // Store is open now at 15:29:01.6129911: True // Store is open at 08:00:00: True -// Store is open at 21:00:00: False +// Store is open at 21:00:00: True // Store is open at 04:59:00: False -// Store is open at 18:31:00: False +// Store is open at 18:31:00: True //