monthsAdded by IBM on August 8, 2013 | Version 1 (Original)
Converts a duration to an equal number of months. Durations may include days and months.
Table 1. months 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, P11M is 11 months. Furthermore, only the year and month values are used by this function. All other values are ignored.
- 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 whole number representing the number of months, or NaN if the input does not match the allowed format.
Example The following model converts years and months into a total number of months. The model contains data elements for years and months. 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 months using the months function. This value is then stored in the <totalTime> element.
<xforms:bind nodeset="totalTime" type="xsd:duration"
calculate="months(concat('P', ../years, 'Y', ../months, 'M'))"/>