Skip to content

Commit

Permalink
subtle bug in the condition (#42633)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stashut authored Sep 17, 2024
1 parent 9ec74a3 commit fadc18d
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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
// </Snippet2>

0 comments on commit fadc18d

Please sign in to comment.