Topic
  • 6 replies
  • Latest Post - ‏2013-05-22T20:51:43Z by arun_tcs
SystemAdmin
SystemAdmin
6772 Posts

Pinned topic timezone converstion

‏2012-05-01T19:28:59Z |
Hi,
I have a requirement, where i need to convert EST time zone to UTC Timezone. The request is going to have MM/DD/YYYY HH24:MI:SS. I need to convert it to xml dateTime format.
Do we have any function in DP which will convert the timezone or do we need to do it manually.
I tried to change the date format with date:format-date($variable, 'Z'), but its returning nothing. SO any direction on this will help.
Updated on 2012-05-02T23:12:16Z at 2012-05-02T23:12:16Z by HermannSW
  • HermannSW
    HermannSW
    4744 Posts

    Re: timezone converstion

    ‏2012-05-01T20:47:36Z  
    Hi,

    please look into "store:///utilities.xsl", or just include it and use dpfunc:zulu-time():
    
    $ echo 
    "<foobar/>" | coproc2 zulu-time.xsl - http:
    //dp2-l3:2223; echo 2012-05-01T20:17:56Z $ $ cat zulu-time.xsl <xsl:stylesheet version=
    "1.0" xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" xmlns:dpfunc=
    "http://www.datapower.com/extensions/functions" extension-element-prefixes=
    "dp" > <xsl:include href=
    "store:///utilities.xsl"/>   <xsl:output omit-xml-declaration=
    "yes" /> <xsl:template match=
    "/"> <xsl:copy-of select=
    "dpfunc:zulu-time()"/> </xsl:template> </xsl:stylesheet> $
    


    That function has two parameters you can make use of:
    
    $ xpath++ 
    "//*[@name='dpfunc:zulu-time']/xsl:param/@name|//*[@name='dpfunc:zulu-time']/xsl:param/@select" utilities.xsl   ------------------------------------------------------------------------------- name=
    "time" ------------------------------------------------------------------------------- select=
    "''" ------------------------------------------------------------------------------- name=
    "include-milliseconds" ------------------------------------------------------------------------------- select=
    "'off'" $
    


     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: timezone converstion

    ‏2012-05-01T21:25:13Z  
    • HermannSW
    • ‏2012-05-01T20:47:36Z
    Hi,

    please look into "store:///utilities.xsl", or just include it and use dpfunc:zulu-time():
    <pre class="jive-pre"> $ echo "<foobar/>" | coproc2 zulu-time.xsl - http: //dp2-l3:2223; echo 2012-05-01T20:17:56Z $ $ cat zulu-time.xsl <xsl:stylesheet version= "1.0" xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" xmlns:dpfunc= "http://www.datapower.com/extensions/functions" extension-element-prefixes= "dp" > <xsl:include href= "store:///utilities.xsl"/> <xsl:output omit-xml-declaration= "yes" /> <xsl:template match= "/"> <xsl:copy-of select= "dpfunc:zulu-time()"/> </xsl:template> </xsl:stylesheet> $ </pre>

    That function has two parameters you can make use of:
    <pre class="jive-pre"> $ xpath++ "//*[@name='dpfunc:zulu-time']/xsl:param/@name|//*[@name='dpfunc:zulu-time']/xsl:param/@select" utilities.xsl ------------------------------------------------------------------------------- name= "time" ------------------------------------------------------------------------------- select= "''" ------------------------------------------------------------------------------- name= "include-milliseconds" ------------------------------------------------------------------------------- select= "'off'" $ </pre>

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    Thanks for the response Herman,
    I tried with the following way

    <xsl:value-of select="dpfunc:zulu-time($bDay,'on')"></xsl:value-of>

    The input i gave is 06/05/2010 20:15:20
    The output i am getting is 1901-12-13T20:45:52.-2147483648Z which is wrong. am i missing anything in passing the arguments.
  • HermannSW
    HermannSW
    4744 Posts

    Re: timezone converstion

    ‏2012-05-02T00:10:11Z  
    Thanks for the response Herman,
    I tried with the following way

    <xsl:value-of select="dpfunc:zulu-time($bDay,'on')"></xsl:value-of>

    The input i gave is 06/05/2010 20:15:20
    The output i am getting is 1901-12-13T20:45:52.-2147483648Z which is wrong. am i missing anything in passing the arguments.
    "06/05/2010 20:15:20" is no standardized date time format to my knowledge, and timezone information is missing.

    Looking into utilities.xsl you can see that "java.util.Date.new()" is called for $time=''.
    This is the same as "dp:time-value()", but with up to 3 digits after decimal point for microsecond resolution
    (https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/now37).
    
    $ echo 
    "<foobar/>"  | xpath++ 
    "java.util.Date.new()" - 1335915793.853 $ $ echo 
    "<t>1335915793.853</t>" | coproc2 zulu-time.2.xsl - http:
    //dp2-l3:2223; echo 2012-05-01T23:43:13.852Z $ $ echo 
    "<t>0</t>" | coproc2 zulu-time.2.xsl - http:
    //dp2-l3:2223; echo 1970-01-01T00:00:00.000Z $
    


    You can convert a data in date-time format to epoch time by "date:seconds()":
    
    $ echo 
    "<d>2012-01-01T00:00:00+01:00</d>"  | xpath++ 
    "date:seconds(.)" - 1325372400 $ echo 
    "<t>1325372400</t>" | coproc2 zulu-time.2.xsl - http:
    //dp2-l3:2223; echo 2011-12-31T23:00:00.000Z $
    


    But you need to convert your input to date-time format first.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: timezone converstion

    ‏2012-05-02T22:32:25Z  
    • HermannSW
    • ‏2012-05-02T00:10:11Z
    "06/05/2010 20:15:20" is no standardized date time format to my knowledge, and timezone information is missing.

    Looking into utilities.xsl you can see that "java.util.Date.new()" is called for $time=''.
    This is the same as "dp:time-value()", but with up to 3 digits after decimal point for microsecond resolution
    (https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/now37).
    <pre class="jive-pre"> $ echo "<foobar/>" | xpath++ "java.util.Date.new()" - 1335915793.853 $ $ echo "<t>1335915793.853</t>" | coproc2 zulu-time.2.xsl - http: //dp2-l3:2223; echo 2012-05-01T23:43:13.852Z $ $ echo "<t>0</t>" | coproc2 zulu-time.2.xsl - http: //dp2-l3:2223; echo 1970-01-01T00:00:00.000Z $ </pre>

    You can convert a data in date-time format to epoch time by "date:seconds()":
    <pre class="jive-pre"> $ echo "<d>2012-01-01T00:00:00+01:00</d>" | xpath++ "date:seconds(.)" - 1325372400 $ echo "<t>1325372400</t>" | coproc2 zulu-time.2.xsl - http: //dp2-l3:2223; echo 2011-12-31T23:00:00.000Z $ </pre>

    But you need to convert your input to date-time format first.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    i tried to fix the timezone in the xslt, I passed the format which it expects
    The input is 2011-12-20T12:00:00-0600. but output is coming as 2012-05-02T22:16:07Z which is not correct
  • HermannSW
    HermannSW
    4744 Posts

    Re: timezone converstion

    ‏2012-05-02T23:12:16Z  
    Thanks for the response Herman,
    I tried with the following way

    <xsl:value-of select="dpfunc:zulu-time($bDay,'on')"></xsl:value-of>

    The input i gave is 06/05/2010 20:15:20
    The output i am getting is 1901-12-13T20:45:52.-2147483648Z which is wrong. am i missing anything in passing the arguments.
    Hi,

    your date is in wrong (Java, RFC 822) format, the colon is missing for XSLT (ISO 8601), see:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/java_simpledateformat_vs_xs_datetime26

    This is how you get the correct output:
    $ echo "<t>2011-12-20T12:00:00-0600</t>" | xpath++ "date:seconds(.)" -
    NaN
    $ echo "<t>2011-12-20T12:00:00-06:00</t>" | xpath++ "date:seconds(.)" -
    1324404000
    $ echo "<t>1324404000</t>" | coproc2 zulu-time.2.xsl - http://dp2-l3:2223; echo
    2011-12-20T18:00:00.000Z
    $ 
    $ grep zulu zulu-time.2.xsl 
        <xsl:copy-of select="dpfunc:zulu-time(.,'on')"/>
    $
    


     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Updated on 2014-03-25T02:57:11Z at 2014-03-25T02:57:11Z by iron-man
  • arun_tcs
    arun_tcs
    144 Posts

    Re: timezone converstion

    ‏2013-05-22T20:51:43Z  
    • HermannSW
    • ‏2012-05-02T23:12:16Z
    Hi,

    your date is in wrong (Java, RFC 822) format, the colon is missing for XSLT (ISO 8601), see:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/entry/java_simpledateformat_vs_xs_datetime26

    This is how you get the correct output:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">$ echo "<t>2011-12-20T12:00:00-0600</t>" | xpath++ "date:seconds(.)" - NaN $ echo "<t>2011-12-20T12:00:00-06:00</t>" | xpath++ "date:seconds(.)" - 1324404000 $ echo "<t>1324404000</t>" | coproc2 zulu-time.2.xsl - http://dp2-l3:2223; echo 2011-12-20T18:00:00.000Z $ $ grep zulu zulu-time.2.xsl <xsl:copy-of select="dpfunc:zulu-time(.,'on')"/> $ </pre>

     
    Hermann <myXsltBlog/> <myXsltTweets/>

    Hello Herman ,

    I am trying to use function dpfunc:zulu-time in store://utilities.xsl , to convert the value returned by the function dp:time-value() to Zulu Format. But am seeing wierd output.

    output :

    <DateTime xmlns:func="http://exslt.org/functions">
       <timeinMilliseconds>1369254819457</timeinMilliseconds>
       <zuluFormat>45359-12-16T16:57:37.000Z</zuluFormat>
    </DateTime>

    I was expecting the to see the current datetime in the below format :

    2013-05-22T15:03:38.381Z

    Please let me know if this is right function to get convert the current time value in milliseconds(returned by dp:time-value()) to Zulu format.

    It would be even better if I can get the date time as per local timezone.

     

    Thanks and Regards,

    Arun

     

     

     

     

     

    Attachments