How to display duration that is in day to second format to years,days,hours, mins format in SAIL interface

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: 

07/01/2019 1:27 PM - 1 yr 31 days 48 mins
03/17/2019 11:59 AM - 1 yr 137 days 2 hrs
Here is the interface code and screenshot for your reference.
a!gridTextColumn(
label: "Duration",
field: "pp.startTime",
data: if(local!datasubset.totalCount=0,{},apply(rule!activeProcessDuration(_),index(index(local!datasubset.data,"pp",{}),
"startTime",{})))
)
Any help is much appreciated.
Thanks,
Meena

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    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.

  • 0
    Certified Lead Developer
    in reply to meenakshir

    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.

Reply Children