Subtract 10 minutes from time input

(Steven Smith) #1

I must be missing an easier way to do this. I’m writing a smart app and I want to subtract 10 minutes from the time input by the user.


log.debug "${starttime}"

//def prepare_time = new Date().parse("yyy-MM-dd'T'HH:mm:ss.SSSZ", starttime)
//log.debug "${prepare_time}"

long starttime_unix = new Date().parse("yyy-MM-dd'T'HH:mm:ss.SSSZ", starttime).getTime() / 1000
log.debug "${starttime_unix}"

long prepare_time = starttime_unix - 600
log.debug "${prepare_time}"

schedule(prepare_time, do_prepare)


starttime is a time input, if I schedule using that, it works.

If I schedule using the commented out prepare_time which is a Date object, it works.

If I convert to a unix timestamp it not long runs at the expected time. Does schedule() not take into account time zone when using a unix timestamp?

Alternatively, is there an easy way to subtract 10 minutes from my Date object and just avoid the unix timestamp all together.

(Mike Maxwell) #2

the unixTimestamp is in ms, not seconds, that could be all that’s going on here

(Steven Smith) #3

Thanks, that was it. I don’t know why I thought that schedule() accepted the timestamp in seconds. It is clearly documented that it is in milliseconds.