Hi,
I have a rule which returns the process duration in interval format.
now()- ri!processStartTime - Given 07/01/2019 1:27 PM as the process start time, it returns
396::00:50:49.264 (which is in day to second format). How do i display this in years, days, hrs, mins?
For eg:
Discussion posts and replies are publicly visible
A while ago I wrote an Expression Rule function that can calculate the gross elapsed seconds from a date/time difference, which can be used for various things including (i assume) what you're looking to do. My only disclaimer is, I don't happen to know whether this is the most efficient way to do this.
a!localVariables( local!days: tointeger(ri!endTime - ri!startTime), local!hours: hour(ri!endTime - ri!startTime), local!minutes: minute(ri!endTime - ri!startTime), local!seconds: second(ri!endTime - ri!startTime), if( local!days = 0, 0, local!days * 24 * 60 * 60 ) + if( local!hours = 0, 0, local!hours * 60 * 60 ) + if( local!minutes = 0, 0, local!minutes * 60 ) + local!seconds )
Here's how I used the above - I was looking for a way to make a grid of tasks show "natural started time" similar to what you see if you view your task list in tempo. I assume you can probably reuse this concept and do some light tweaking to make it do what you're after.
/* display natural time, ie the timestamps that appear on the task list */ a!localVariables( local!elapsedSeconds: rule!TEST_elapsedSeconds( startTime: ri!time, endTime: now() ), local!elapsedMinutes: floor(local!elapsedSeconds / 60), local!elapsedHours: floor(local!elapsedSeconds / 3600), local!weekdayNames: {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}, local!timeDecision: where({ local!elapsedSeconds < 30, local!elapsedSeconds < 60, local!elapsedSeconds < 3600, local!elapsedSeconds < (3600 * 24), local!elapsedSeconds < (3600 * 24 * 2), local!elapsedSeconds < (3600 * 24 * 7), true() /* all other date/times */ }), /*local!elapsedSeconds & char(10) & local!timeDecision & char(10) &*/ choose( local!timeDecision[1], "A moment ago", "Less than a minute ago", local!elapsedMinutes & if(local!elapsedMinutes > 1, " minutes", " minute") &" ago", local!elapsedHours & if(local!elapsedHours > 1, " hours", " hour") &" ago", "Yesterday, " & totime(local(ri!time)), index(local!weekdayNames, weekday((ri!time), 1), "") & ", " & totime(local(ri!time)), todate(local(ri!time)) & ", " & totime(local(ri!time)) ) )
I tried the rule and it gives the following error:
Expression evaluation error: Syntax error. Details: Expression evaluation error: Keyword and non-keyword arguments must not be mixed. Used in: localVariables.
Please post a screenshot of what you're trying.
Here is the test rule i created with the code you provided. I get the error when testing the rule.
Also, when i use within the interface which has the exact code , i get the same error.
Please note that we are in 18.2 version. Thanks again for your help.
Since you're pre-19.2, you need to change a!localVariables() to with() instead. Everything else can stay the same I believe.