-
-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
15 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]> | ||
|
@@ -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); | ||
} | ||
} | ||
} | ||
} |