Devs,
I've hit writers block I guess. I've been pounding away at this for a few hours. It seems it should be simple to do but I keep hitting brick walls.
I want to set a state variable containing the date/time 30 minutes into the future.
When a function runs, I want to check and see if the current date/time is after that future date/time.
state.futureDate = new Date() + 30.minutes
checkDate()
def checkDate() {
def currentDate = new Date()
if (state.futureDate < currentDate) {
log.debug "The future has passed"
return true
}
else {
log.debug "The future has not arrived"
return false
}
}
I figured it out finally. Sometimes when you make a post you work even harder or think in a different direction to figure it out.
This solution works with the time in the long data type format. It calculates milliseconds for time. -1 and below means the time has passed which can also be used to figure out how much time (in milliseconds) has passed if needed.
def 30min = (30 * 60000) // 30 minutes (1,800,000 milliseconds) in the future)
state.futureDate = new Date().getTime() + 30min
checkDate()
def checkDate() {
def currentDate = new Date().getTime()
def timeDiff = state?.futureDate - currentDate
if (timeDiff < 0 || timeDiff == null) {
log.debug "The future has passed or the future is null"
return true
}
else {
log.debug "The future has not arrived"
return false
}
}