Page 1 of 1
triggertime versus getDate
Posted: 27 Jun 2014 12:34
by skiptannen
I'm sure this is a really stupid question, and I'll kick myself when I find out the answer, but what is the usage difference between triggertime and getDate? I've been using getDate for the current date and time, but I'm curious since I see triggertime in so many script examples.
Thank you.
Re: triggertime versus getDate
Posted: 27 Jun 2014 13:36
by Martin
Hi,
Not a stupid question at all since it can make a big difference in some cases.
triggertime contains the point of time when the trigger detected the event. Function getDate() returns the current point of time when the function is executed.
The difference is important when a flow runs for a long time:
-trigger ...
-action Notification on Screen: {triggertime,dateformat,HH:mm:ss} --> 15:20:37
-action Sleep: 10s
-action Notification on Screen: {triggertime,dateformat,HH:mm:ss} --> 15:20:37
-trigger ...
-action Notification on Screen: {getDate(),dateformat,HH:mm:ss} --> 15:20:37
-action Sleep: 10s
-action Notification on Screen: {getDate(),dateformat,HH:mm:ss} --> 15:20:47
Using triggertime can also be useful in cases where one action writes a file with the time in the file name and another action wants to read the same file again:
-action Write to File: /storage/emulated/0/file_{triggertime,dateformat,HHmmss}.txt
-action Init Variable Text File: /storage/emulated/0/file_{triggertime,dateformat,HHmmss}.txt
The two actions above should always produce the same file name, regardless of the duration it takes to execute the first action. The actions will not work as intended with getDate() since the device time can change between the two actions.
Regards,
Martin
Re: triggertime versus getDate
Posted: 27 Jun 2014 14:25
by skiptannen
Thanks Martin - excellent description. I totally get it now and I can see where triggertime will make more sense in some of my flows.