Topic
  • 11 replies
  • Latest Post - ‏2015-02-18T16:52:54Z by HermannSW
NeelamGK
NeelamGK
3 Posts

Pinned topic Timezone conversion.

‏2013-05-17T16:16:36Z |

How do I go about converting a time in epoch time to a given timezone.

I have these 2 values

<scheduledStartTime>1361568600000</scheduledStartTime>

<timeZone>America/Chicago</timeZone>

I need to convert this into a datetime.

Any ideas ?

I know there is a java function for this.But that does not help in Datapower.

Thanks,

Neelam.

  • HermannSW
    HermannSW
    4903 Posts

    Re: Timezone conversion.

    ‏2013-05-19T01:55:53Z  

    XPath2 function fn:adjust-dateTime-to-timezone would be helpful:
    http://www.w3.org/TR/xpath-functions/#func-adjust-dateTime-to-timezone

    That will be available with XQuery 1.0 support in DataPower V6.0 firmware, but cannot help you right now.

     

    Conversion of your epoch time value (times 1000) to date-time can be done this way (for Zulu time):

    $ echo "<scheduledStartTime>1361568600000</scheduledStartTime>" | xpath++ "date:add('1970-01-01T00:00:00',date:duration(. div 1000))" -
    2013-02-22T21:30:00
    $
     

    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

  • NeelamGK
    NeelamGK
    3 Posts

    Re: Timezone conversion.

    ‏2013-05-20T20:31:45Z  

    Thanks for the update, Hermann.

  • NeelamGK
    NeelamGK
    3 Posts

    Re: Timezone conversion.

    ‏2015-01-07T03:30:10Z  
    • HermannSW
    • ‏2013-05-19T01:55:53Z

    XPath2 function fn:adjust-dateTime-to-timezone would be helpful:
    http://www.w3.org/TR/xpath-functions/#func-adjust-dateTime-to-timezone

    That will be available with XQuery 1.0 support in DataPower V6.0 firmware, but cannot help you right now.

     

    Conversion of your epoch time value (times 1000) to date-time can be done this way (for Zulu time):

    $ echo "<scheduledStartTime>1361568600000</scheduledStartTime>" | xpath++ "date:add('1970-01-01T00:00:00',date:duration(. div 1000))" -
    2013-02-22T21:30:00
    $
     

    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

    Hermann, 

     

    Now that firmware 6.0 is out, do we have a way to do this conversion from epoch time to a particular timezone(CST) or EST ?

     

    Thanks,

    Neelam.

  • HermannSW
    HermannSW
    4903 Posts

    Re: Timezone conversion.

    ‏2015-01-07T11:15:11Z  
    • NeelamGK
    • ‏2015-01-07T03:30:10Z

    Hermann, 

     

    Now that firmware 6.0 is out, do we have a way to do this conversion from epoch time to a particular timezone(CST) or EST ?

     

    Thanks,

    Neelam.

    Hi Neelam,

    Now that firmware 6.0 is out,
    >
    that is good, should read as "Now that 6.0.0, 6.0.1, 7.0.0 and 7.1.0 is out" ;-)

     

    do we have a way to do this conversion from epoch time to a particular timezone(CST) or EST ?
    >
    Yes, with 6.0.0.0 XQuery compiler is available, and every valid XPath 2.0 statement is a valid XQuery script..

    I just took the 5th example from the spec:
    http://www.w3.org/TR/xpath-functions/#func-adjust-dateTime-to-timezone

    As you can see here it just works (2225 is the XQuery endpoint of coproc2 service):

    $ echo 'adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00-07:00"),'\
    > 'xs:dayTimeDuration("PT10H"))' | coproc2 - dummy.xml http://dp2-l3:2225; echo
    2002-03-08T03:00:00+10:00
    $
    

     

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> <Viz.js_form10/> | <xqib/> | <myCE/> <myFrameless/> | 

    Updated on 2015-01-07T11:37:24Z at 2015-01-07T11:37:24Z by HermannSW
  • tallurisri
    tallurisri
    105 Posts

    Re: Timezone conversion.

    ‏2015-01-14T20:40:42Z  
    • HermannSW
    • ‏2015-01-07T11:15:11Z

    Hi Neelam,

    Now that firmware 6.0 is out,
    >
    that is good, should read as "Now that 6.0.0, 6.0.1, 7.0.0 and 7.1.0 is out" ;-)

     

    do we have a way to do this conversion from epoch time to a particular timezone(CST) or EST ?
    >
    Yes, with 6.0.0.0 XQuery compiler is available, and every valid XPath 2.0 statement is a valid XQuery script..

    I just took the 5th example from the spec:
    http://www.w3.org/TR/xpath-functions/#func-adjust-dateTime-to-timezone

    As you can see here it just works (2225 is the XQuery endpoint of coproc2 service):

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">$ echo 'adjust-dateTime-to-timezone(xs:dateTime("2002-03-07T10:00:00-07:00"),'\ > 'xs:dayTimeDuration("PT10H"))' | coproc2 - dummy.xml http://dp2-l3:2225; echo 2002-03-08T03:00:00+10:00 $ </pre>

     

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> <Viz.js_form10/> | <xqib/> | <myCE/> <myFrameless/> | 

    Hi Hermann,

    I am trying to format dateTime value in response content for one of the webservice exists in DataPower XI52 v6.0.02.

    I am trying to use below xslt code to format date, but some reason "adjust-dateTime-to-timezone" function was not returning any date.

    Can you please suggest that how can i fix this.

     

    XSLT Code:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
    xmlns:fn="http://www.w3.org/TR/xpath-functions">
    <xsl:variable name="rspdate" select="//last_update_date"/>
    <xsl:variable name="formatdate" select="adjust-dateTime-to-timezone($rspdate,fn:dayTimeDuration('-PT6H'))"/>
    <!-- Identity transform -->
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
    </xsl:template>
          <xsl:template match="//last_update_date">
           <last_update_date>
            <xsl:value-of select="$formatdate"/>
            </last_update_date>
    </xsl:template>
    </xsl:stylesheet>

     

     

    Thanks.

    Sri

     

  • HermannSW
    HermannSW
    4903 Posts

    Re: Timezone conversion.

    ‏2015-01-14T21:42:08Z  

    Hi Hermann,

    I am trying to format dateTime value in response content for one of the webservice exists in DataPower XI52 v6.0.02.

    I am trying to use below xslt code to format date, but some reason "adjust-dateTime-to-timezone" function was not returning any date.

    Can you please suggest that how can i fix this.

     

    XSLT Code:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
    xmlns:fn="http://www.w3.org/TR/xpath-functions">
    <xsl:variable name="rspdate" select="//last_update_date"/>
    <xsl:variable name="formatdate" select="adjust-dateTime-to-timezone($rspdate,fn:dayTimeDuration('-PT6H'))"/>
    <!-- Identity transform -->
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
    </xsl:template>
          <xsl:template match="//last_update_date">
           <last_update_date>
            <xsl:value-of select="$formatdate"/>
            </last_update_date>
    </xsl:template>
    </xsl:stylesheet>

     

     

    Thanks.

    Sri

     

    Hi,

    DataPower has a XSLT 1.0 processor, that uses XPath 1.0 with EXSLT and propriatary extension funtions.

    adjust-dateTime-to-timezone() is a XPath 2.0 funtion, that is only available in DataPower XQuery processor.

    If you want to use that function you have to

    • either write a XQuery script instead of XSLT
    • or call XQuery script via  dp:xquery-transform(_, _)  from within XSLT (available in ≥7.0.0.0 firmwares only)

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> <Viz.js_form10/> | <xqib/> | <myCE/> <myFrameless/> | 

  • tallurisri
    tallurisri
    105 Posts

    Re: Timezone conversion.

    ‏2015-01-14T22:41:01Z  
    • HermannSW
    • ‏2015-01-14T21:42:08Z

    Hi,

    DataPower has a XSLT 1.0 processor, that uses XPath 1.0 with EXSLT and propriatary extension funtions.

    adjust-dateTime-to-timezone() is a XPath 2.0 funtion, that is only available in DataPower XQuery processor.

    If you want to use that function you have to

    • either write a XQuery script instead of XSLT
    • or call XQuery script via  dp:xquery-transform(_, _)  from within XSLT (available in ≥7.0.0.0 firmwares only)

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> <Viz.js_form10/> | <xqib/> | <myCE/> <myFrameless/> | 

    Hi Hermann,

    Thanks for your quick response. 

    At this point we are still using v6, i will try with XQuery.

    Customer requirement is like this:

    Actual date comes in response in zulu format (2015-01-14T21:30:19.000Z), but customer want to see in local time(2015-01-14T15:30:19 -06;00).

    I am new to Xquery do you think is there any easier way to do this in XSLT instead of Xquery?

    any help would be app appreciated.

    Thank you,

    Sri.

  • HermannSW
    HermannSW
    4903 Posts

    Re: Timezone conversion.

    ‏2015-01-15T01:31:26Z  

    Hi Hermann,

    Thanks for your quick response. 

    At this point we are still using v6, i will try with XQuery.

    Customer requirement is like this:

    Actual date comes in response in zulu format (2015-01-14T21:30:19.000Z), but customer want to see in local time(2015-01-14T15:30:19 -06;00).

    I am new to Xquery do you think is there any easier way to do this in XSLT instead of Xquery?

    any help would be app appreciated.

    Thank you,

    Sri.

    Hi Sri,

    as with XSLT you start with an identity transform, this time for XQuery:
    http://en.wikipedia.org/wiki/Identity_transform#Using_XQuery_2


    Here you can see that adapted XQuery script (attached) does what is needed:

    $ coproc2 adjustTZ.xq zulu.xml http://dp2-l3.boeblingen.de.ibm.com:2225; echo
    <?xml version="1.0" encoding="UTF-8"?>
    <e><f><last_update_date>2015-01-14T15:30:19-06:00</last_update_date></f></e>
    $ 
    $ cat zulu.xml 
    <e><f><last_update_date>2015-01-14T21:30:19.000Z</last_update_date></f></e>
    $
    


    Here is syntax highlighted source view:

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> <Viz.js_form10/> | <xqib/> | <myCE/> <myFrameless/> | 

    Attachments

  • tallurisri
    tallurisri
    105 Posts

    Re: Timezone conversion.

    ‏2015-01-15T21:40:44Z  
    • HermannSW
    • ‏2015-01-15T01:31:26Z

    Hi Sri,

    as with XSLT you start with an identity transform, this time for XQuery:
    http://en.wikipedia.org/wiki/Identity_transform#Using_XQuery_2


    Here you can see that adapted XQuery script (attached) does what is needed:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">$ coproc2 adjustTZ.xq zulu.xml http://dp2-l3.boeblingen.de.ibm.com:2225; echo <?xml version="1.0" encoding="UTF-8"?> <e><f><last_update_date>2015-01-14T15:30:19-06:00</last_update_date></f></e> $ $ cat zulu.xml <e><f><last_update_date>2015-01-14T21:30:19.000Z</last_update_date></f></e> $ </pre>


    Here is syntax highlighted source view:

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> <Viz.js_form10/> | <xqib/> | <myCE/> <myFrameless/> | 

    Hi Hermann,

    Thanks for your quick help, i will try with this XQuery.

     

     

  • GuptaVineet
    GuptaVineet
    1 Post

    Re: Timezone conversion.

    ‏2015-02-18T16:19:12Z  
    • HermannSW
    • ‏2015-01-15T01:31:26Z

    Hi Sri,

    as with XSLT you start with an identity transform, this time for XQuery:
    http://en.wikipedia.org/wiki/Identity_transform#Using_XQuery_2


    Here you can see that adapted XQuery script (attached) does what is needed:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">$ coproc2 adjustTZ.xq zulu.xml http://dp2-l3.boeblingen.de.ibm.com:2225; echo <?xml version="1.0" encoding="UTF-8"?> <e><f><last_update_date>2015-01-14T15:30:19-06:00</last_update_date></f></e> $ $ cat zulu.xml <e><f><last_update_date>2015-01-14T21:30:19.000Z</last_update_date></f></e> $ </pre>


    Here is syntax highlighted source view:

     

    Hermann <myBlog/> <myTweets/> | <GraphvizFiddle/> <Viz.js_form10/> | <xqib/> | <myCE/> <myFrameless/> | 

    Hi Hermann, 

     

    Can we use java extenstions like java.text.SimpleDateFormat is being used in store://utilities.xsl. I need to take care of DayLight Savings Time while changing the timezone.  I want to implement something like this in DataPower 6.0 appliance. 

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date, date1;
    date = sdf.parse("2006-05-01");
     
    System.out.println(TimeZone.getTimeZone("CST").inDaylightTime(date));

    When i am trying to use java extensions DataPower is not complaining but its also not returning any value. Also, I am using Datapower firmware 6.0. Can you please help ?

     

    Thanks

    Vineet

     

  • HermannSW
    HermannSW
    4903 Posts

    Re: Timezone conversion.

    ‏2015-02-18T16:52:54Z  

    Hi Hermann, 

     

    Can we use java extenstions like java.text.SimpleDateFormat is being used in store://utilities.xsl. I need to take care of DayLight Savings Time while changing the timezone.  I want to implement something like this in DataPower 6.0 appliance. 

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date date, date1;
    date = sdf.parse("2006-05-01");
     
    System.out.println(TimeZone.getTimeZone("CST").inDaylightTime(date));

    When i am trying to use java extensions DataPower is not complaining but its also not returning any value. Also, I am using Datapower firmware 6.0. Can you please help ?

     

    Thanks

    Vineet

     

    Hi,

    the few "Java" functions in DataPower are just convenience alternative namings to DataPower extension functions -- there is no Java in DataPower firmware. Reason you do not se anything is that XSLT default for calling something unknown is to just ignore it. 

    Best bet you have on 6.0 is making use of the huge amount of XPath 2.0 date/time functions as mentioned above.

    In case you will be on ≥7.0.0.0 firmware you can even execute XPath 2.0 statements from within XSLT via dp:xquery-transform(), or you can make use of GatewayScript.


    Hermann.

    Updated on 2015-02-18T16:54:00Z at 2015-02-18T16:54:00Z by HermannSW