Detecting if I am between two different times

I am trying to adjust a smartapp to be able to ignore triggers within certain times.

currently I am just playing around with the code to get what I want

def startTime = timeToday(starting, location.timeZone)
def endTime = timeToday(ending, location.timeZone)

 if (now() < endTime.time && now() > startTime.time) { "NOW BETWEEN TIMES"

The issue I have of course, is if the start time is before midnight and the end time is after midnight… since they all basically fall into Today.

How should I adjust the code to add a day to date if the end time falls after midnight and the start time is before midnight?

Try this, I use it to know if I need to go back to night mode when the bedroom door is shut

def checkTime() {
log.debug "Checking time and performing actions"

// if between the start and end time, send the correct Hello Home Phrase
if(timeOfDayIsBetween(timeStart, timeEnd, (new Date()), location.timeZone))
    // after the time and the trigger went; talk to house
    log.debug "sent $HHPhrase"


That seems to work! Thank you!

I was also just now able to get this to work:

if (startTime > endTime) { = + 1

But your method is cleaner, thanks!