<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://schema.infor.com/InforOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://xml.apache.org/saxon/java" xmlns:tfs="http://www.infor.com/tfs" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.pnp-software.com/XSLTdoc" exclude-result-prefixes="java tfs" xmlns:ext="com.infor.tfs.mappings.extensions.XsltExt">
	<!---->
	<!--********************************************************************************************************************-->
	<!-- Calculates the time difference for two given dates + 1 day. The format of the dates is: YYYYMMDD  -->
	<!--********************************************************************************************************************-->
	<xd:doc>
		<xd:short>Returns the duration for a <b>DateFrom</b>, <b>DateTo</b> and a <b>Duration</b>.</xd:short>
		<xd:detail>The format of <b>dateFrom</b> and <b>dateTo</b> is YYYYMMDD. <b> The duration</b> is added to the dateTo.<br/>
		This means that if dateFrom and dateTo are equal and the duration is P1D the return is P1D. This corresponds to a daily demand.
		</xd:detail>
		<xd:param name="dateFrom" type="String">Start date.</xd:param>
		<xd:param name="dateTo" type="String">End date.</xd:param>
		<xd:param name="days" type="String">Number of days which will added to the difference.</xd:param>
	</xd:doc>
	<xsl:function name="tfs:getDateDifference"  as="xs:string">
		<xsl:param name="dateFrom"/>
		<xsl:param name="dateTo"/>
		<xsl:param name="days"/>
			<xsl:variable name="date1" select="xs:date(ext:parseDate($dateFrom, 'yyyyMMdd', 'yyyy-MM-dd'))"></xsl:variable>
			<xsl:variable name="date2" select="xs:date(ext:parseDate($dateTo, 'yyyyMMdd', 'yyyy-MM-dd')) + xs:dayTimeDuration($days)"></xsl:variable>
		<xsl:value-of select="$date2 - $date1" />
	</xsl:function>
</xsl:stylesheet>
