What's the Time Mr BPEL?

What's the Time Mr BPEL?

Seems that often in BPEL you have a process that has some sort of time dependency.  Examples are :
  • Response must be given in 5 days.
  • Product must be shipped to arrive by 12 October 2007.
  • How old will a child born on 19th January 1995 be on 1 September 2007?
Lets quickly review how we deal with these.

XML Date Formats

XML dateTime takes the form 'YYYY-MM-DDTHH:MM:SS+Z:ZZ' So 7:30PM 6 July 2007 in UK is '2007-07-06-T19:30:00+01:00', the '+01:00' indicates that this is in a timezone one hour ahead of UTC or GMT in old money.  This is because of British Summer Time moving the clock one hour forward.  We could also represent this time as the following
  • 2007-07-06-T20:30:00+02:00 - Paris summer time
  • 2007-07-06-T11:30:00-07:00 - San Francisco summer time
However the following is not necessarily identical
  • 2007-07-06-T19:30:00 - indeterminate time zone
Note all the fields other than the timezone must be present in a dateTime type.
In addition to dateTimes we can also specify duration types that take the form 'PyyYmmMddDThhHmmMssS'.  Apart from the initial P and the T is hours, minutes  or seconds are being specified all fields are optional.  This gives us time periods such as
  • P7D - a week
  • P1M - a month
  • P1Y1DT1H1S - One year, one day, one hour and one second
  • PT5M - five minutes
Note that unlike real life, 5 minutes does not mean wait until I am ready!


The time now can be obtained by using XPath 2.0 functions.  In January of this year XPath 2.0 finally became a W3C recommendation (W3C standard).  Oracle BPEL PM already implements many of the XPath2.0 functions (usually prefixed with  xp20).  The following functions (documented here) can be used in assign statements and xslt transforms to get the current date and/or time.
  • xp20:current-dateTime() - returns a dateTime element that has the current date and time as formatted above.
  • xp20:current-date() - returns a date element that has the current date as formatted above without the time portion.
  • xp20:current-time() - returns a time element that has the current time formatted as above without the date portion.
So now we know what time it is!

Period of time later/earlier

So how do we calculate a period of time a given time period earlier or later than we actually have.  To do this in XPath 2.0 we could just use the addition (+) and subtraction (-) operators but they also have corresponding XPath functions that are available to use as shown below:
  • xp20:add-dayTimeDuration-to-dateTime(dateTime as string, duration as string)
  • xp20:subtract-dayTimeDuration-from-dateTime(dateTime as string, duration as string)
When using in an assign statement it will be necessary to use the 'ora:getNodeValue()' function to extract the underlying value from an dateTime or duration element.  So to get a day 10 days in the future from today we could use the expression
  • xp20:add-dayTimeDuration-to-dateTime(xp20:current-dateTime(), 'P10D')
So now we can calculate dates relative to another date.

Calculating Differences

In XPath 1.0 this was tricky!  In XPath 2.0 it is built in functionality.  See this post by Ramkumar Menon for details of how to calculate a difference using XPath 2.0 in a stylesheet.  Make sure when doing this you set the versin of the stylesheet to be '2.0' or it won't work.  I haven't got this function to work in an assign statement yet, hence my custom XPath function that does work in an assign statement.
  • ajr:getTimeDifference(earlier as string, later as string)

Answering the questions

So lets look at those questions again :
  • Response must be given in 5 days.
    • Response must be given in a time period 'P5D' or
    • Response must be given by xp20:add-dayTimeDuration-to-dateTime(xp20:current-dateTime(), 'P5D')
  • Product must be shipped to arrive by 12 October 2007.
    Assuming shipping takes 2 days
    • Ship by xp20:subtract-dayTimeDuration-from-dateTime('2007-10-12T00:00:00', 'P2D')
  • How old will a child born on 19th January 1995 be on 1 September 2007?
    • Use a stylesheet set to version 2.0 to calculate (xsd:date('2007-09-01')-xsd:date('1995-01-19')) or
    • use custom xpath function ajr:getTimeDifference('2007-09-01', '1995-01-19')
So now we can go and set timers or notification alerts for these dates and times.  So date processing isn't really as scary as it first seems.  So must go, Its dinnertime!

PS If someone can tell me how to get the xpath 2.0 operators working in assign statements I would be a happy man.


Hi, nice clarification on dates and times. I have a question about the implicit timezone. How is this set, where does it come from. I have a problem in that I believe my timezone should be BST i.e. +01:00 but it isn't, this is causing problems because an hour is being added in later processes? thanks for any help!

There seems to be a problem with timezones and daylight savings time.  I know you have already found Tech Note 395324.1 that gives a work around.  An alternative workaround is to use a custom XPath function to create a new date-time object as I suggested in my EMail.

Posted by Terry Hagan on July 23, 2007 at 09:51 PM MDT #

<antony>PS If someone can tell me how to get the xpath 2.0 operators working in assign statements I would be a happy man. </antony> Response: This is currently not supported. But here is my understanding of the way it works. BPEL allows you to specify the queryLanguage and expressionLanguage that is being used in the process definition. These are defined by the "queryLanguage" and "expressionLanguage" attributes on the <process> element. Orabpel supports XPath 1.0 by default. [These attributes are not present on the <process> element by default]. If you open up the graphical view of the Proess, and double click on the central pane [outside of the "main" sequence], you can get to see a dialog that lists these properties. There, you can notice the expression/queryLanguage URI to be "http://www.w3.org/TR/1999/REC-xpath-19991116" - which is the URI for XPath 1.0. If you wish to use XPath 2.0 as the expressionLanguage/queryLanguage, you need to set these attribtues on the <process> element in the BPEL. The value should be "http://www.w3.org/TR/2007/REC-xpath20-20070123". Unfortunately, BPEL compiler complains that it does not support the language, and hence you would not be able to proceed any further. So, I assume the only way is to use XSLT for all XPath 2.0 needs. Good luck! Ram

Posted by Ramkumar Menon on August 07, 2007 at 08:21 AM MDT #

Just received this from Martien van den Akker of Darwin-IT Professionals

I've seen with xp20:upper-case() that working on a document that comes right out of a receive from a partnerlink/adapter it won't work. But when you copy the document to a different variable, you can do an assign or switch-expressions with xp20:upper-case() and the variable as an input. Possibly the same counts for the datetime functions. It seems to me that it has something to do with the scope of the input-documents.


Posted by Antony Reynolds on February 19, 2008 at 11:11 PM MST #

Hi, I tried to use the mentioned datetime function: xp20:add-dayTimeDuration-to-dateTime() in a BPEL assign activity, but the function never returned a result nor a error message is shown. I tried the following syntax: 1) xp20:add-dayTimeDuration-to-dateTime(xp20:current-dateTime(), 'PT1D') 2) xp20:add-dayTimeDuration-to-dateTime(string(xp20:current-dateTime()), string('PT1D')) 3) xp20:add-dayTimeDuration-to-dateTime(ora:getNodeValue(xp20:current-dateTime()), 'PT1D') As I have to compile and deploy this BPEL process everytime when I changed the syntax, I am already nerved and tired in using xpath functions. Any ideas, or should I return to plain ordinary cool working JAVA functions? BR, Peter

Posted by Peter on March 18, 2008 at 11:16 PM MDT #

I would add that to add secondos we should add one decimal place,like: 'PT30.0S' Otherwise it is not eaten by bpel (v10.1.3)

Posted by Sergio Mendes on August 20, 2008 at 06:33 AM MDT #

please i need to correctly convert from xsd:date to xsd:dateTime on bpel! pls can you help?

Posted by guest on May 31, 2011 at 01:14 AM MDT #

Post a Comment:
Comments are closed for this entry.

Musings on Fusion Middleware and SOA Picture of Antony Antony works with customers across the US and Canada in implementing SOA and other Fusion Middleware solutions. Antony is the co-author of the SOA Suite 11g Developers Cookbook, the SOA Suite 11g Developers Guide and the SOA Suite Developers Guide.


« July 2016