Time Elapsed

What is the recommended approach to get the time elapsed (inside the createTimer function) since a the createTimer was created?

I have several timers. Do I need to create an array to store all the createTimer start times?

*inside the rule*

garageGateTimer = createTimer(now.plusMinutes(10), [|
	if (GF_Garage_Gate.state == OPEN) {
		timeElapsed = ????????????
		Global_Message.sendCommand("Garage Gate remains OPEN " + timeElapsed)
		garageGateTimer.reschedule(now.plusMinutes(10))
	}
])

Two possible approaches

val fred = now
val duration = 10
createTimer(now.plusMinutes(duration)) [ |
    logInfo("test", "timer was started " + fred.toString)
    logInfo("test", "duration was " + duration.toString)
]

I’m trying to figure out how to account for the ‘reschedule’. Do you recommend to just add the minutes to a number variable with each reschedule rather than calculate the actual elapsed time based on the original ‘now’?

Well, you can’t add to the val, and you can’t use a var created inside the rule in this way.
You could use a ‘global’ var,but only if you are using xxx.rules files.
If you have many, that could take the form of a Map (“array”) as you suggested to begin with.

Or the timestamp works, just find the difference to current ‘now’ as and when required.
Possibly useful methods

or the traditional way is to convert everything to epoch milliseconds and do simple arithmetic.

Thanks, I will try this on Monday.