Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 6th, 2013, 12:06 AM
Registered User
 
Join Date: Jun 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default POSIX time

Hi,

I'm new to XSLT. I have to write a stylesheet to convert an xml to xhtml format.

The xml has some POSIX/UNIX times in it. I wonder whether there is any XSLT function which will convert a POSIX time value to a date/time value? POSIX is a fairly standard time format.

My value (5881113510280167424) is a 64 bit number - a seconds/nanoseconds pair. It's possible to work out the date if I use some bit manipulation (get the number of seconds and then work out the year, month, day, etc).

Are there any XSLT math operators that will do LEFT/RIGHT SHIFT? What about bitwise AND?
 
Old June 6th, 2013, 02:21 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Multiply your number by something like xs:dayTimeDuration('PT1S') to get a duration in seconds, then add the magic dateTime('1970-01-01T00:00:00Z') to get the corresponding date/time.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 6th, 2013, 04:27 AM
Registered User
 
Join Date: Jun 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by mhkay View Post
Multiply your number by something like xs:dayTimeDuration('PT1S') to get a duration in seconds, then add the magic dateTime('1970-01-01T00:00:00Z') to get the corresponding date/time.
Thanks for your response. However, when I multiply my number with xs:dayTimeDuration('PT1S') I get an overflow error. The result must be greater than 64 bits.
 
Old June 6th, 2013, 04:33 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If your number is in nanoseconds rather than seconds, then divide it by 10^9 first. However, limits on range and precision for durations depend on the processor you are using.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 6th, 2013, 05:07 AM
Registered User
 
Join Date: Jun 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is a POSIX number, so the top 32 bits represents the number of seconds since 1 Jan 1970 and the next 32 bits represent the nanoseconds part of the current second.

How do I get at the top 32 bits in XSLT? In C/C++ I do this: x >> 32 where x represents the number.
 
Old June 6th, 2013, 04:53 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Just divide by 2^32.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading Chapter 3 project takes a long time to load first time!! 999csharp BOOK: Beginning ASP.NET Web Pages with WebMatrix 2 April 6th, 2013 09:07 AM
Do vb exe files time out after a certain period of time? sanderson Visual Basic 2008 Essentials 0 June 11th, 2009 06:48 PM
Time Shift time in minus time out lechalas Beginning VB 6 1 August 11th, 2008 01:56 PM
time zone & day light time rajn ASP.NET 1.0 and 1.1 Professional 0 August 7th, 2007 05:02 PM
Using xs:time to generate time in desired format krayan001 XSLT 0 June 27th, 2005 04:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.