xsl-list
[Top] [All Lists]

Re: [xsl] difference between an integer and current-dateTime()

2020-03-27 07:18:36
I hope this helps.

. . . . . Ken

~/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:output method="text"/>

<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,'&#xa;'"/>
  <xsl:value-of select="'Then:',format-dateTime( $epoch +
                             xs:dayTimeDuration( concat('PT',$oldTime,'S') ),
                            '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]'),'&#xa;'"/>
  <xsl:value-of select="'Current:',$now,'&#xa;'"/>
  <xsl:value-of select="'Current dateTime:',current-dateTime(),'&#xa;'"/>
  <xsl:value-of select="'Difference:', $now - $oldTime,'&#xa;'"/>
  <xsl:value-of select="'Half-way:', ($now - $oldTime) div 2,'&#xa;'"/>
  <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]'),'&#xa;'"/>
</xsl:template>

</xsl:stylesheet>
~/t $


At 2020-03-27 10:34 +0000, Mukul Gandhi gandhi(_dot_)mukul(_at_)gmail(_dot_)com 
wrote:
Hi all,
  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 |
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>