I have a situation where I'd like to write a call template that takes 2 xs:date values as the input and returns the duration in days. This is very simple and I fully understand how to accomplish this. The problem I have is that I would like to IGNORE the extra day occurs in a leap year.
For example if I have 2 Dates such as follows:
Code:
<Dates>
<BeginDate>2010-08-10</BeginDate>
<EndDate>2013-08-10</EndDate>
</Dates>
Since 2012 is a leap year there's an extra day. So it returns from the day-from-duration() function. "1096". I would actually like "1095". Of course if it spans multiple leap years, I would want to remove all the extra leap year days from the result.
Currently I have a very simple call as follows:
Code:
<xsl:template name="getDuration">
<xsl:param name="BeginDate" as="xs:date"/>
<xsl:param name="EndDate" as="xs:date"/>
<xsl:value-of select="days-from-duration($EndDate - $BeginDate)" />
</xsl:template>
I have some ideas about how to accomplish this, but they are all complicated. Perhaps setting up a table of leap years, check the start and end dates to see if they occur before or after Feb 28th of those leap years, and storing how many extra days are between them. Then I would just subtract that result from the days-from-duration() result.
Are there any simple methods that are part of XSLT/XPath that I can make use of to make this easier? I'm running Saxon 8.9 XSLT 2.0 compatible.
Thanks!