Created
February 24, 2016 20:53
-
-
Save JohnyDays/0f344d52fc3035ab04e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function timeIsWithinTimeFilter (time, time_filter) { | |
var start_hour = time_filter.start_hour | |
var start_minutes = time_filter.start_minutes | |
var end_hour = time_filter.end_hour | |
var end_minutes = time_filter.end_minutes | |
if (start_hour > end_hour || | |
(start_hour === end_hour && start_minutes > end_minutes) | |
) { | |
//Time wraps around multiple days | |
return ((time.getHours() > start_hour || | |
(time.getHours() === start_hour && time.getMinutes() >= start_minutes)) || | |
(time.getHours() < end_hour || | |
(time.getHours() === end_hour && time.getMinutes() <= end_minutes)) | |
) | |
} | |
else { | |
//Time doesn't wrap around multiple days | |
return ((time.getHours() > start_hour || | |
(time.getHours() === start_hour && time.getMinutes() >= start_minutes)) && | |
(time.getHours() < end_hour || | |
(time.getHours() === end_hour && time.getMinutes() <= end_minutes)) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment