Subject: Re: [xsl] difference between an integer and current-dateTime() From: "G. Ken Holman g.ken.holman@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 27 Mar 2020 12:18:30 -0000 |
~/t $ xslt2 unixtime.xsl unixtime.xsl Given: 1585039138 Then: 2020-03-24T08:38:58 Current: 1585296916.838 Current dateTime: 2020-03-27T08:15:16.838-04:00 Difference: 257778.838 Half-way: 128889.419 Half-way dateTime: 2020-03-25T20:27:07 ~/t $ cat unixtime.xsl <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:template match="/"> <xsl:variable name="oldTime" select="1585039138"/> <xsl:variable name="epoch" select="xs:dateTime('1970-01-01T00:00:00')"/> <xsl:variable name="now" select="xs:duration(current-dateTime()-$epoch) div xs:dayTimeDuration('PT1S')"/>
<xsl:value-of select="'Given:',$oldTime,'
'"/> <xsl:value-of select="'Then:',format-dateTime( $epoch + xs:dayTimeDuration( concat('PT',$oldTime,'S') ), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]'),'
' "/> <xsl:value-of select="'Current:',$now,'
'"/> <xsl:value-of select="'Current dateTime:',current-dateTime(),'
'"/> <xsl:value-of select="'Difference:', $now - $oldTime,'
'"/> <xsl:value-of select="'Half-way:', ($now - $oldTime) div 2,'
'"/> <xsl:value-of select="'Half-way dateTime:', format-dateTime( $epoch + xs:dayTimeDuration( concat('PT',$oldTime + ( ($now - $oldTime) div 2 ),'S') ), '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]'),'
'"/> </xsl:template>
</xsl:stylesheet> ~/t $
Hi all, B B I've got a number 1585039138 for example (which is number of seconds since epoch 1970-01-01T00:00:00Z UTC). I wish to find the duration (in minutes or seconds) between previous number and current-dateTime(). I wish to do this with XSLT (2/3 both are fine with me, preferably non schema aware). I expect this difference to be always positive, since the number will change depending on what moment (at any moment, I wish to find this difference) it is calculated. How can I do that?
-- Regards, Mukul Gandhi <http://www.mulberrytech.com/xsl/xsl-list>XSL-List info and archive <http://lists.mulberrytech.com/unsub/xsl-list/96802>EasyUnsubscribe (<>by email)
-- Contact info, blog, articles, etc. http://www.CraneSoftwrights.com/s/ | Check our site for free XML, XSLT, XSL-FO and UBL developer resources | Streaming hands-on XSLT/XPath 2 training class @ US$45 (5 hours free) | Essays (UBL, XML, etc.) http://www.linkedin.com/today/author/gkholman |
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] difference between an int, G. Ken Holman g.ken. | Thread | Re: [xsl] difference between an int, Dimitre Novatchev dn |
Re: [xsl] difference between an int, Martin Honnen martin | Date | [xsl] [ANN] Balisage Papers Due Apr, B Tommie Usdin btusd |
Month |