Supported Version: 1 XML Definition: date.duration.xml Source: date.duration.function.xsl
This implementation relies on date:seconds() being available in order to get the current date/time. If it isn't, it gives a zero duration (for now).
Source<func:function name="date:duration">
<xsl:param name="seconds">
<xsl:choose>
<xsl:when test="function-available('date:seconds')">
<xsl:value-of select="date:seconds()" />
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:variable name="duration">
<xsl:variable name="day-s"
select="60 * 60 * 24" />
<xsl:variable name="hour-s"
select="60 * 60" />
<xsl:variable name="min-s"
select="60" />
<xsl:if test="$seconds < 0">-</xsl:if>
<xsl:text>P</xsl:text>
<xsl:variable name="s"
select="$seconds * ((($seconds >= 0) * 2) - 1)" />
<xsl:variable name="days"
select="floor($s div $day-s)" />
<xsl:variable name="hours"
select="floor(($s - ($days * $day-s)) div $hour-s)" />
<xsl:variable name="mins"
select="floor(($s - ($days * $day-s) - ($hours * $hour-s)) div $min-s)" />
<xsl:variable name="secs"
select="$s - ($days * $day-s) - ($hours * $hour-s) - ($mins * $min-s)" />
<xsl:if test="$days">
<xsl:value-of select="$days" />
<xsl:text>D</xsl:text>
</xsl:if>
<xsl:if test="$hours or $mins or $secs">T</xsl:if>
<xsl:if test="$hours">
<xsl:value-of select="$hours" />
<xsl:text>H</xsl:text>
</xsl:if>
<xsl:if test="$mins">
<xsl:value-of select="$mins" />
<xsl:text>M</xsl:text>
</xsl:if>
<xsl:if test="$secs">
<xsl:value-of select="$secs" />
<xsl:text>S</xsl:text>
</xsl:if>
</xsl:variable>
<func:result select="string($duration)" />
</func:function> Change HistorySubmitted: 2001-05-12 Creator: Jeni Tennison(http://www.jenitennison.com/)
Returns the result of converting the argument number of seconds to a duration string, or the current date/time as a duration since 1970-01-01T00:00:00Z.
Version | Modified | By | Details |
---|
1.1 | 2001-06-11 | Jeni Tennison |
Added Javascript implementation.
| 1.2 | 2001-06-12 | Jeni Tennison |
Added implementations in XSLT and EXSLT - Functions.
| 1.3 | 2001-06-16 | Jeni Tennison | - Updated Javascript implementation.
- Added Microsoft-specific stylesheet.
| 1.4 | 2002-08-21 | Craig Stewart | Added libxslt implementation to the list. |
|