secondsAdded by IBM on August 8, 2013 | Version 1 (Original)
Converts a duration to an equal number of seconds. Durations may include days, hours, minutes, and seconds.
Table 1. seconds parameter
|duration||xsd:duration||a duration, written in the following format:
For example, P1Y3M3DT12H34M21S is: 1 year, 3 months, 3 days, 12 hours, 34 minutes, and 21 seconds.
If any of the values are zero, they may be omitted. For example, P120D is 120 days. Furthermore, the year and month values are ignored by this function.
The T designator may only be absent if there are no time elements. The P designator must always be present.
The number of seconds may include a decimal fraction.
- P marks the string as a duration.
- nY gives the number of years.
- nM gives the number of months.
- nD gives the number of days.
- T separates the date from the time.
- nH gives the number of hours.
- nM gives the number of minutes.
- nS gives the number of seconds.
Returns A number (possibly fractional) representing the number of seconds, or NaN if the input does not match the allowed format.
Example The following model converts days, hours and minutes into a total number of minutes. The model contains data elements for days, hours, and minutes. The user types these values into fields that are linked to the data elements. When data is entered, the xforms:bind uses the concat function to turn the data into a formatted duration string, converts that string to seconds using the seconds function, and then divides by sixty to convert the time to minutes. This value is then stored in the <totalTime> element.
<xforms:bind nodeset="totalTime" type="xsd:duration"
calculate="seconds(concat('P', ../days, 'DT', ../hours, 'H',
../minutes, 'M')) div 60"/>