How to exclude weekend days from Timed Event's duration?


#1

Hello all,

in a customer workflow we have a “Time Intermediate Catch Event” to wait for a period of time, e.g. 3 days (P3D).

      <bpmn:timerEventDefinition>
        <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">P3D</bpmn:timeDuration>
      </bpmn:timerEventDefinition>

Now we got the request, that this period should only include working days from Monday to Friday.
So if the time starts on Friday the weekend should not count and the expiration should happen on Wednesday of the following week, not on Monday.
Any to achieve this through the model using scripting or something like this?

Or is the only way to write a method to calculate the expiration date of the Timed event?

Regards, Frank


#2

Hi @langfr,

there is not Out-Of-The-Box solution. The engine has plugin point to register your own BusinessCalendar. Have a look at the package https://github.com/camunda/camunda-bpm-platform/tree/master/engine/src/main/java/org/camunda/bpm/engine/impl/calendar.

The dafault calendars are registered in the ProcessEngineConfigurationImpl: https://github.com/camunda/camunda-bpm-platform/blob/2bd5b44213e3637fe12797591837b9a1afdc8feb/engine/src/main/java/org/camunda/bpm/engine/impl/cfg/ProcessEngineConfigurationImpl.java#L2103-L2112

You could register your own business calender in a process engine plugin.

Hope this helps,

Ingo


#3

Ingo, thanks for your support. Very interesting option to be used in the future.

For just to skip the weekend days as expiration data of a time I fiddled out this apporach:

  • create an input parameter of date type, set the value with a goovy script
  • use the input parameter’s value as the expiration date.
    <bpmn:intermediateCatchEvent id="TimerIntermediateCatchEvent" name="warten bis zum nächsten Werktag" camunda:asyncBefore="true">
      <bpmn:extensionElements>
        <camunda:inputOutput>
          <camunda:inputParameter name="dueDate">
            <camunda:script scriptFormat="groovy">import org.joda.time.DateTime

//
// create a Joda DateTime object, add 1 day to create dueDate
//
def dueDate = new DateTime(new java.util.Date() ).plusDays(1)
// skip to next weekday
while ( dueDate.getDayOfWeek() &gt; 5 ) {
    dueDate.plusDays(1);
}
//
// return the result which will create the local task variable for the timer definition
//
dueDate</camunda:script>
          </camunda:inputParameter>
        </camunda:inputOutput>
      </bpmn:extensionElements>
...
      <bpmn:timerEventDefinition>
        <bpmn:timeDate xsi:type="bpmn:tFormalExpression">${dueDate.toString()}</bpmn:timeDate>
      </bpmn:timerEventDefinition>
    </bpmn:intermediateCatchEvent>

Regards, Frank


#4

The bigger problem I have found is there is no good business calendar lib for java :-1:t2: