Skip to main content
sarahb0004
March 28, 2023
Question

How to create a rule to check if the time is within range

  • March 28, 2023
  • 10 replies
  • 0 views

I need some help to create an expression rule to check if my given time is within the range. For example, my process model will start running today at 6PM then should stop running at 5AM the next day. Now I need to create a validation where it returns true/false to check if the execution time is still within the range. Hope anyone could help me. Thank you.

    10 replies

    stefanhelzle0001
    Brainy
    March 28, 2023

    What exactly is your question? How to check the date, that would be "start >= date <= end"? Or is it about starting your process? What exactly do you mean with "start running today at 6PM then should stop running at 5AM the next day"?

    In general it is a best practice to just start processes in a certain interval and then have a XOR to check whether this exact moment in time is valid or not. But this depends on your actual use case.

    sarahb0004
    March 28, 2023

    I have a process model to run batch process which automatically triggers at 6PM today and should only run until 5AM the next day. It's looping it's own to collect another data before submitting it to the subprocess model. Now my question is, how to form a script that returns true/false to check if the execution time is still within the time range which is 6PM today until 5AM the next day. So the next time my process model calls itself again and it 5:01 AM, it should proceed on the end node.

    Hope I made it clear. Thank you for your time.

    stefanhelzle0001
    Brainy
    March 28, 2023

    Did you try to add a XOR gateway using a condition of "now() > pv!endDate"? I simple date comparison evaluates to your desired true/false.

    Now, your can calculate the endDate using the a!addDateTime() function in the initial start and pass it along to the next calls.

    March 28, 2023

    Agree with Stefan.. When you are looping to restart the execution just put an XOR gate and check the time. If it's more than 5am, end the process

    sarahb0004
    March 28, 2023

    Hello there, I already have the XOR my problem is how to put a logic where the xor will redirect to end node if the time is beyond 5AM. If I use the logic now() > totime("5:00 AM") and the time is 12:00 AM onwards, then 12:00 AM > 5:00 AM is false which will lead to ending the process model early than the expected time limit. I came up with this script instead. I am just not confident with the logic if it's appropriate

    a!localVariables(
        local!dateTime: right(text(ri!timeNow,"hh:mm AM/PM"),2),
        local!castTime: cast(8, local(ri!timeNow)),
        if(
          local!dateTime = "AM",
          local!castTime < totime("5:00 AM"),
          local!castTime > totime("5:00 AM")
        ) 
      )

    March 28, 2023

    can you use something like this?

    localvariable(
    local!currentTime: now(),
    local!finalTime:time(5,0,0,0),
    
    timevalue(local!currentTime)