xsl-list
[Top] [All Lists]

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

2012-05-21 11:07:56
  Hi,

  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
following:

    <xsl:function name="my:current-timestamp" as="xs:string">
       <!-- the UNIX epoch -->
       <xsl:variable name="epoch" select="xs:dateTime('1970-01-01T00:00:00Z')"/>
       <!-- 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)"/>
       <xsl:variable 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)"/>
    </xsl:function>

  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().

  Regards,
 
-- 
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


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