What’s the best way to determine if the current time of day is between two values, specifically when those values cross midnight? For example: if (currentTime is between 8PM and 3AM)
I’ve tried timeOfDayIsBetween, but it seems to compare the full DateTime object. So something like this: timeOfDayIsBetween(timeToday("20:00"), timeToday("03:00"), new Date(), location.timeZone) return true when the current time is between 3AM and 8PM, rather than the other way around. (I may be wrong about that, but I think that’s what I’ve seen so far.)
I’ve done more complicated things like this:
def startToday = timeToday("20:00")
def endToday = timeToday("03:00")
if (endToday <= startToday) {
use (TimeCategory) {
endToday = endToday + 1.day
}
}
if (timeOfDayIsBetween(startToday, endToday, new Date(), location.timeZone)
But that seems like overkill. Is there an easier way to do this?
In webCoRE it helps sometimes to use the opposite condition when the times span midnight. That is, if the current time is NOT between 03:00 and 20:00 (which IS between 20:00 and 03:00, spanning midnight). That keeps the start and end times on the same day. Just a thought. Not sure if that helps.