Skip to content

Instantly share code, notes, and snippets.

@JohnyDays
Created February 24, 2016 20:53
Show Gist options
  • Save JohnyDays/0f344d52fc3035ab04e4 to your computer and use it in GitHub Desktop.
Save JohnyDays/0f344d52fc3035ab04e4 to your computer and use it in GitHub Desktop.
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