The BirtDuration class provides functions to get parts of time periods, or durations, used in XML documents. The durations are specified in the following form:
PnYnMnDTnHnMnS
where
P indicates the period (required).
nY indicates the number of years.
nM indicates the number of months.
nD indicates the number of days.
T indicates the start of a time section (required if the duration includes hours, minutes, or seconds).
nH indicates the number of hours.
nM indicates the number of minutes.
nS indicates the number of seconds.
For example, the following value indicates a duration of 2 years, 3 months, and 5 days:
P2Y3M5D
The following value indicates a duration of 10 hours:
PT10H
The BirtDuration class is static. The application cannot create instances of the class.
BirtDuration.add
This function adds two durations together, and returns the sum.
String. The first duration to use in the comparison.
lexicalDuration2
String. The second duration to use in the comparison.
Returns
Integer. Partial order relation between the two durations. Returns 1 if the first duration is greater, 0 if they are equal and -1 if the second duration is greater.
Examples
The following expressions compare the lengths of specific durations:
String. A duration from which to get the hours value.
Returns
An integer that represents the hours value of the specified duration.
Examples
The following examples show the hour values returned for specific durations:
BirtDuration.hour( "P1Y15DT12H" ) // returns 12
BirtDuration.hour( "P5Y2M" ) // returns 0
BirtDuration.isLongerThan
This function tests if a duration is longer than another duration. Sometimes the order relationship between certain durations cannot be determined, for example, one month (P1M) and 30 days (P30D), or one year (P1Y) and 365 days (P365D). In cases such as these, the function returns false.
This function tests if a duration is shorter than another duration. Sometimes the order relationship between certain durations cannot be determined, for example, one month (P1M) and 30 days (P30D), or one year (P1Y) and 365 days (P365D). In cases such as these, the function returns false.
This function returns the number of milliseconds in a given duration, from a specified start date. The number of milliseconds in a duration can change depending on the start date. For example, a duration of one month can be 28, 29, 30, or 31 days, depending on the start date. If the start date is January 1, the function calculates the milliseconds between January 1 and February 1 (excluding February 1), which equals 2678400000 milliseconds or 31 days. If the start date is February 1, 2009 (a leap year), the function calculates the milliseconds between February 1 and March 1, which equals 2505600000 milliseconds or 29 days.
Syntax
Number BirtDuration.timeInMills( string lexicalDuration, Date startDate )
Parameters
lexicalDuration
String. A duration whose length in milliseconds to get.
startDate
Date object. Represents the start date.
Returns
Number object. The number of milliseconds in the specified duration.
Examples
The following examples show the number of milliseconds returned for specific durations and start dates: