[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] The UNIX epoch, or time since Jan 01, 1970

Subject: [xsl] The UNIX epoch, or time since Jan 01, 1970
From: Florent Georges <lists@xxxxxxxxxxxx>
Date: Mon, 21 May 2012 17:06:49 +0100 (BST)


  As part of sending an OAuth request to connect to Twitter, I have to
get a timestamp, as the number of seconds elapsed from Jan 01, 1970
(AKA the
UNIX epoch).  The simplest solution I could come with is the

<xsl:function name="my:current-timestamp" as="xs:string">
       <!-- the UNIX
epoch -->
       <xsl:variable name="epoch"
       <!-- time since then -->
       <xsl:variable name="diff"  select="current-dateTime() - $epoch"/>     
 <!-- all components, in seconds... -->

       <xsl:variable name="days"
 select="days-from-duration($diff) * (24*60*60)"/>
name="hours" select="hours-from-duration($diff) * (60*60)"/>
 <xsl:variable name="mins"  select="minutes-from-duration($diff) * 60"/>
 <xsl:variable name="secs"  select="floor(seconds-from-duration($diff))"/>
   <!-- sum each of them -->
       <xsl:sequence select="xs:string($days +
$hours + $mins + $secs)"/>

  It looks to me like this is
rather complex to get such a timestamp.
Did I miss something?  Is there a way
to simplify this?  If not, and
because this is a kind of value (unfortunately)
still used in recents
API, it would probably be interesting to add a new
specifier for it in
the picture string format for fn:format-dateTime().

Florent Georges

Current Thread