From 5cf73ac1939474d57b0629167ad608d43fa2f1a5 Mon Sep 17 00:00:00 2001 From: drippypop <146481814+drippypop@users.noreply.github.com> Date: Fri, 18 Oct 2024 08:24:08 -0400 Subject: [PATCH] Update TimeExtensions.cs --- src/DateTimeExtensions/TimeExtensions.cs | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/DateTimeExtensions/TimeExtensions.cs b/src/DateTimeExtensions/TimeExtensions.cs index 73d120c4..4ba597e4 100644 --- a/src/DateTimeExtensions/TimeExtensions.cs +++ b/src/DateTimeExtensions/TimeExtensions.cs @@ -1,4 +1,4 @@ -#region License +#region License // // Copyright (c) 2011-2012, João Matos Silva @@ -46,21 +46,22 @@ public static Time TimeOfTheDay(this DateTime dateTime) public static bool IsBetween(this DateTime dateTime, Time startTime, Time endTime) { var currentTime = dateTime.TimeOfTheDay(); - //start time is lesser or equal than end time - if (startTime.CompareTo(endTime) <= 0) - { - //currentTime should be between start time and end time - if (currentTime.CompareTo(startTime) >= 0 && currentTime.CompareTo(endTime) <= 0) - { + // If startTime and endTime are equal + if (startTime.Equals(endTime)) { + if (currentTime.CompareTo(startTime) >= 0 && currentTime.CompareTo(endTime) <= 0) { return true; } - return false; } - else - { - //currentTime should be between end time time and start time - if (currentTime.CompareTo(startTime) >= 0 || currentTime.CompareTo(endTime) <= 0) - { + // Start time is lesser or equal than end time + if (startTime.CompareTo(endTime) <= 0) { + // CurrentTime should be between start time and end time + if (currentTime.CompareTo(startTime) >= 0 && currentTime.CompareTo(endTime) <= 0) { + return true; + } + return false; + } else { + // CurrentTime should be between end time and start time + if (currentTime.CompareTo(startTime) >= 0 || currentTime.CompareTo(endTime) <= 0) { return true; } return false; @@ -86,4 +87,4 @@ public static Time ToTimeOfDay(this string timeValueString) return Time.Parse(timeValueString); } } -} \ No newline at end of file +}