Skip to content

Commit

Permalink
Update TimeExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
drippypop authored Oct 18, 2024
1 parent 4deb0e7 commit 5cf73ac
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/DateTimeExtensions/TimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region License
#region License

//
// Copyright (c) 2011-2012, João Matos Silva <[email protected]>
Expand Down Expand Up @@ -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;
Expand All @@ -86,4 +87,4 @@ public static Time ToTimeOfDay(this string timeValueString)
return Time.Parse(timeValueString);
}
}
}
}

0 comments on commit 5cf73ac

Please sign in to comment.