Date operations
This utility performs date calculations by adding or subtracting a specified number of days from a given date.
Background
The template converts the Gregorian date to a Julian Day Number (JDN), applies the specified day offset, and converts the result back to a Gregorian date.
Call template
Add the template for date operations to your main template, eg. <xsl:import href="utility-date-operations.xsl"/>.
The named template date-operations accepts two parameters:
givenDate- [required] The input date inYYYY-MM-DDformat (optional time component supported).daysDiff- [required] The number of days to add or subtract.
To add or subtract days form a date, call the utility template like this:
<xsl:call-template name="date-operations">
<xsl:with-param name="givenDate" select="$today" />
<xsl:with-param name="daysDiff" select="14" />
</xsl:call-template>
The resulting date is returned in YYYY-MM-DD format and can be passed to the format-date utility for custom formatting.
Possible errors
If “NaN” is displayed instead of the expected date, this usually has one of two causes:
- The supplied date is missing or does not contain a valid date.
- The referenced node or variable name is incorrect.