triggertime variable formatting

Post your questions and help other users.

Moderator: Martin

Post Reply
ariloc
Posts: 109
Joined: 05 Jun 2016 21:36

triggertime variable formatting

Post by ariloc » 09 Mar 2017 00:00

There's something I have never understood about: get date and time from the triggertime variable. I searched around the whole forum and didn't find anything that worked.

I want to know the actual time formatted in a conventional way. Then I want to use the expression condition to check out if the time is the one that I want to be (it's on a multiple time trigger flow). I know that I can use the time range condition but seems unpractical to me. For example, to check if it's 10:30, time range condition between 10:29 and 10:31. And I don't want that.

There's a useful solution?

User avatar
Bingwu
Posts: 114
Joined: 26 Feb 2016 10:26

Re: triggertime variable formatting

Post by Bingwu » 09 Mar 2017 07:55

Hello!

Maybe I did not understand your problem, but change the condition "time range" to 10:30 to 10:30.

greeting
Peter

User avatar
Bingwu
Posts: 114
Joined: 26 Feb 2016 10:26

Re: triggertime variable formatting

Post by Bingwu » 09 Mar 2017 12:24

Hello!

Perhaps the following will help you.
The script (for a subsequent condition) is not particularly elegant, but it works.

The basis is the variable "getDate()" which provides the date and time in milliseconds.
(A change to "triggertime" would also be possible, since both variables are based on the date and time in milliseconds from 1970-01-01 00:00:00.)

"getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")" removes the date from "getDate()" and returns the time in milliseconds.

The rest of the script converts the result into a "understandable" decimal number [hours],[minutes] (Variable "time").

The decimal places are "real minutes" (60 units, not 100 units). (10:30 = 10,30 not 10:30 = 10,50)

Variant 1 (Script):
hour = (getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000;
minute = floor((((getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 36000.) - (hour * 100)) / 100. * 60.);
time = hour + (minute / 100.)
Variant 2, compact (Script):
time = ((getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000) + (floor((((getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 36000.) - (((getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000) * 100)) / 100. * 60.) / 100.)
(The point behind some numbers forces the calculation with decimal places!)

I wish you success!

greeting
Peter
-----------------------------------------------------------------------------------------------------------------------------------------
(I can master this strange language better, so once again in the original!) :lol:

Hallo!

Vielleicht hilft dir Folgendes weiter.
Das Script (für eine nachfolgende Condition) ist nicht besonders elegant, aber es funktioniert.

Grundlage ist die Variable "getDate()", welche das Datum und die Uhrzeit in Millisekunden liefert.
(Eine Umstellung auf "triggertime" wäre aber auch möglich, da beiden Variablen das Datum und die Zeit in Millisekunden ab 1970-01-01 00:00:00 zugrunde liegt.)

"getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")" entfernt das Datum aus "getDate()" und liefert die Zeit in Millisekunden.

Der übrige Teil des Scripts wandelt das Ergebnis in eine "verständliche" Dezimalzahl [Stunden],[Minuten] um (Variable "time").

Die Nachkommastellen sind "echte Minuten" (60er-Einheiten, nicht 100er-Einheiten). (10:30 = 10,30 nicht 10:30 = 10,50)

Variante 1 (Script):
hour = (getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000;
minute = floor((((getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 36000.) - (hour * 100)) / 100. * 60.);
time = hour + (minute / 100.)
Variante 2, kompakt (Script):
time = ((getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000) + (floor((((getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 36000.) - (((getDate() - getDate("{getDate(),dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000) * 100)) / 100. * 60.) / 100.)
(Der Punkt hinter einigen Zahlen erzwingt die Berechnung mit Nachkommastellen!)

Viel Erfolg!

Gruß
Peter

ariloc
Posts: 109
Joined: 05 Jun 2016 21:36

Re: triggertime variable formatting

Post by ariloc » 09 Mar 2017 18:17

Thank you! But I need a script that not only works with actual date but also with any time that Automagic manipulates.

Another problem I have got is when I use the Input Dialog, Time type. The retrieved value needs to be formated to HH:mm. With that, I want to subtract it to the actual time and get the difference between both times. Then, format that to put it on an sleep action. That way I can make Automagic wait until the time specified and finally do a determinate action.

It can be applied in multiple situations so it's perfect for every Automagician. Can you help me with that?

User avatar
Bingwu
Posts: 114
Joined: 26 Feb 2016 10:26

Re: triggertime variable formatting

Post by Bingwu » 09 Mar 2017 20:10

Hello!

The scripts work with all date/time-data from Automagic, if they are formatted accordingly:
(For example: 2017-03-07 10:58:49,254 pm = 1488916729254 in Automagic)

If you want to calculate with the values, then you have to change the script slightly, so that 10:30 becomes 10.5. or 10:45 becomes 10.75 (For this you have to remove only "/ 100 * 60".)
Please do not ask for a ":" between hours and minutes. :shock:

So it should be somewhat more understandable.

Variant 1 (Script):
(For example: "value" from "Input Dialog")
anydatetimeinautomagic = value;
hour = (anydatetimeinautomagic - getDate("{anydatetimeinautomagic,dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000;
minute = floor(((anydatetimeinautomagic - getDate("{anydatetimeinautomagic,dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 36000.) - (hour * 100));
time = hour + (minute / 100.)
Variant 2, compact (Script):
(For example: "value" from "Input Dialog")
anydatetimeinautomagic = value;
time = ((anydatetimeinautomagic - getDate("{anydatetimeinautomagic,dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000) + (floor(((anydatetimeinautomagic - getDate("{anydatetimeinautomagic,dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 36000.) - (((anydatetimeinautomagic - getDate("{anydatetimeinautomagic,dateformat,yyyy-MM-dd}","yyyy-MM-dd")) / 3600000) * 100)) / 100.)
regards
Peter

User avatar
Scotty
Posts: 78
Joined: 26 Aug 2016 20:29
Location: Southern California

Re: triggertime variable formatting

Post by Scotty » 09 Mar 2017 22:36

As alternatives to the suggestions from Peter:
ariloc wrote:I want to know the actual time formatted in a conventional way.
To express, in a "conventional" (hour:minute) format, the time at which the flow was triggered:

Action / Script
Trighour="{triggertime,dateformat,HH}";
Trigmin="{triggertime,dateformat,mm}";

ariloc wrote:Then I want to use the expression condition to check out if the time is the one that I want to be (it's on a multiple time trigger flow). I know that I can use the time range condition but seems unpractical to me. For example, to check if it's 10:30, time range condition between 10:29 and 10:31. And I don't want that.
Then, to determine if the triggertime matches the time that you want (in the example I am providing, it returns TRUE if the flow was triggered at 7:54AM - otherwise, it returns FALSE):

Condition / Expression
"{Trighour}:{Trigmin}" == "07:54";

ariloc
Posts: 109
Joined: 05 Jun 2016 21:36

Re: triggertime variable formatting

Post by ariloc » 09 Mar 2017 23:02

Thank you a lot! And sorry Peter, I'm actually beginner at scripts and that stuff.

User avatar
Bingwu
Posts: 114
Joined: 26 Feb 2016 10:26

Re: triggertime variable formatting

Post by Bingwu » 10 Mar 2017 08:51

Hallo Ariloc und hallo Scotty!
Thank you a lot! And sorry Peter, I'm actually beginner at scripts and that stuff.
No problem! I'm still a beginner too, especially with the script language (and english)! :) This was my first attempt as I tortured myself with the time.

Scotty has kindly described the possibility of querying the exact time.
But now I know ;) how to extract a time from an automagic-date/time to query time ranges without the date.

Have fun
Peter

Post Reply