Calculating date and time values for your business process model

Calculating date and time values for your business process model

When you design and implement your business process model with the OpenText Process Suite platform (f.k.a. Cordys Business Operations Platform), you can manipulate the process data stored in XML in the so-called message map. 

While working in the message map you create assignments to the data elements of your process, and you can use XPath expressions to manipulate these data. Specifically when addressing date and time values, you can use various date and time functions supported by the Rule Engine. In this blog, I want to explore some of the features and illustrate these through working examples.

For reference purposes I have put each XPath expression on a new line. This enables to simply copy the expression into the XPath expression editor and use it as a starting point for any additional change you wish to make yourself:

Calculating_date_and_time_values_for_a_business_process_model_IMAGE

time()

The time() function does not seem to be documented in the online documentation. Judging by its returning values, this function returns an integer value representing the hours and minutes of GMT (Greenwich Mean Time). For example, at 1:01 PM (13:01) GMT the time() function returns 1301.


date()

The date() function returns an integer value representing the number of days since 1 January 1 AD, by default when no date value specified, it refers to the current system date, e.g. date(2015, 8, 15) while today is August 15-th, 2105. Using the date() function you can make day difference calculations.

 

Note that we will apply the date of August, 15-th, 2015 to represent the current date. Thus date(2015, 8, 15) returns 735825, this is the number of days since January 1-st of the year 1 AD.

 

Alos note that we use the sprint() function to refer to the current year rather than hard coding year:

sprintf("%D(%yyyy)",utc())

You can replace %yyyy by %MM or %dd to refer to the number of month or day, e.g. 08 for August, and 15 for August 15-th.

 

Returning the number of days until the current months end:

date(sprintf("%D(%yyyy)",utc()),sprintf("%D(%MM)",utc())+1,1)-1-date()

 

However this gives an error while in December, so you will need to add a condition to the expression correct for the month of December:

if (sprintf("%D(%MM)",utc()) = 12) then date(sprintf("%D(%yyyy)",utc()),12, 31) - date() else date(sprintf("%D(%yyyy)",utc()),sprintf("%D(%MM)",utc())+1,1)-1-date()

 

How many days until this year's end?

date(sprintf("%D(%yyyy)",utc()),12,31) - date()

Or using the alternative format (yyyy-MM-ddTHH:mm:ss) to refer to the date of year's end:

date(concat(sprintf("%D(%yyyy)", utc()), "-12-31T00:00:00")) - date()

 

Using date() to calculate the number of days between any two dates:

date(2015,3,31) - date(2015,2,1)

Or using the sprintf() function to refer to the current year:

date(sprintf("%D(%yyyy)",utc()),3,31) -date(sprintf("%D(%yyyy)",utc()),2,1)

 

Using date() to determine working day or weekend

if (date() mod 7 >= 6) then "Weekend day" else "Working day"

Applying the default date August 15-th, 2015 will return “Weekend day”.

if (date(2015,08,15) mod 7 >= 6) then "Weekend day" else "Working day"


utc() or utcgmt()

The two functions utc() and utcgmt() both return an integer value representing the number of seconds that elapsed since January 1-st, 1970 with reference to the current date time or GMT date and time. If you want to know the time difference between your local time zone versus GMT, you can use utc() and utcgmt() returning:

utc() - utcgmt()

Returns the number of seconds between your local time and GMT.

Alternatively, to return the seconds in minutes or hours:

(utc() - utcgmt()) div 60 (3600)

returns the number of minutes (hours) of the time difference.

 

Using utc() you can calculate and format the current date while adding a fortnight:

sprintf("%D(%yyyy-%MM-%dd)", utc()+604800*2)

Where 604800 is the number of seconds denoting 1 week, and thus times 2, 3, 4, etc. enables you to add any number of weeks. For example to generate a formatted date reflecting a four weeks payment term from the current date:

sprintf("%D(%yyyy-%MM-%dd)", utc()+604800*4).

 

Using utc() to get a time difference between two times in seconds. Referring to our default date, you calculate the difference in seconds:

utc(2015,08,31,0,0,0) - utc(2015,8,15,0,0,0)

returns 1382400 seconds.

By including the div operator in the expression you recalculate this to minutes (60), hours (3600), days (86400), etc. depending on the value you use with the div operator

(utc(2015,08,31,0,0,0) - utc(2015,8,15,0,0,0)) div 86400

 

sprintf()

Returning the years quarter using a formatted month based on the utc() current date value while applying the numeric functions ceiling() or floor():

ceiling(sprintf("%D(%MM)",utc()) div 3)

floor((sprintf("%D(%MM)",utc()) + 2) div 3)


Using the startTime value of the process instance

The startTime value of the process instance included in the process instance properties represents the utc() integer value of the start time of the process suffixed by three additional positions for the number of milliseconds. If you want to format the startTime value with the correct utc value, you need to strip these additional three numerical characters using the substring() function and extracting the first 10 positions. Finally, with the sprint() function, you present the start date and time of the process instance in an eligible format again:

sprintf("%D(%yyyy-%MM-%dd)T%T(%HH:%mm:%ss.0)", substring(instance:instanceProperties/instance:startTime/text(),1,10), substring(instance:instanceProperties/instance:startTime/text(),1,10))


In addition to the date and time functions illustrated here, you can call any static Java method in the expression, this has been described in one of our previous blogs: http://info.convedo.com/tech-talk/using-java-methods-in-a-business-process-model


Don't miss out on future blog posts! Subscribe to email updates today!

tech talk blog