Page 1 of 1
Regarding the variable triggertime
Posted: 18 Aug 2019 19:11
by akhileshg1988
Could someone please tell me in what format is the triggertime stored?
This will help you guys understand my query:-
For a trigger that triggered at 2019-08-18 12:47:23.763, the variable triggertime stores the value 1566112643763.
How is the latter related to the former?
Re: Regarding the variable triggertime
Posted: 19 Aug 2019 05:59
by Desmanto
Automagic save the time as android Millis (Miliseconds). Android Millis is based on unix epoch time, but has been multiplied by 1000 for the miliseconds. So 1566112643763 means 1566112643763 miliseconds has passed since 1 January 1970, which is the 0 based. If you add that up, you get 2019-08-18 07:17:23.763.
Wait, why you have different result? Because the add up using UTC timezone, which is UTC+0. You are using UTC+5.5, so this add another 5,5 hours to the time, become 2019-08-18 12:47:23.763. I am using UTC+7, hence I get 2019-08-18 14:17:23.763
Because the getDate() already taking account the timezone, the millis usually is not exactly that miliseconds since 1 January 1970, unless you are in UTC+0. DST also affect the millis. But the time shown is always correct, only the millis is affected by timezone. This should be considered when you are doing calculation directly to the millis.
Beside that, Automagic automagically convert any number that is bigger than the current time - 20 years in millis. Based on today 19 August 2019, then it is around 24 August 1999, with value around 935,000,000,000 (span of 20 years x 365d, no leap year). If you have time less than this, it will shows up as number, not datetime.
Re: Regarding the variable triggertime
Posted: 19 Aug 2019 10:35
by akhileshg1988
Thanks for enlightening me on that one.
I have another query though.
I have been trying to create a flow that would calculate the duration of a call.
In this regard, could you please help me as to how to subtract two times?
For example, the time at which a call ends is 04:08 PM and the call had started at 03:49 PM.
How can I subtract the latter time from the former one so that the result obtained is 19 minutes i.e. the duration of the call?
Re: Regarding the variable triggertime
Posted: 19 Aug 2019 10:59
by Desmanto
if both of the time are retrieved from triggertime, simply subtract them. Since those 2 events happen in different trigger, you have to save the first trigger's triggertime in glovar. Create a flow with trigger incoming/outgoing call - offhook (picked up/call connected), then script
Then to get the ended call, use another flow with another trigger incoming/outgoing call - ended (call ended/rejected), then script
Code: Select all
duration = triggertime - global_start_call;
durstring = getDurationString(duration);
{duration} is in miliseconds. To get it in string, you have to use the function getDurationString(). So if the call is 3 minutes 30 seconds, then {duration} is 210000 and {durstring} is "3m 30s".
The flexibility of adding/subtracting the time makes it better to keep the time in its datetime type. Until the end of the flow, when we are going to present it in UI, then we use dateformat or getDurationString().
Re: Regarding the variable triggertime
Posted: 20 Aug 2019 07:45
by akhileshg1988
Thanks!
It worked.
That was a lot of help.