Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IsBetween method in TimeExtensions.cs #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
}
Loading