triggertime versus getDate

Post your questions and help other users.

Moderator: Martin

Post Reply
skiptannen
Posts: 82
Joined: 13 Jan 2014 21:39

triggertime versus getDate

Post by skiptannen » 27 Jun 2014 12:34

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.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: triggertime versus getDate

Post by Martin » 27 Jun 2014 13:36

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

skiptannen
Posts: 82
Joined: 13 Jan 2014 21:39

Re: triggertime versus getDate

Post by skiptannen » 27 Jun 2014 14:25

Thanks Martin - excellent description. I totally get it now and I can see where triggertime will make more sense in some of my flows.

Post Reply