Reputation: 31
I have the following variable:
<xsl:variable name="time">
<xsl:value-of select="'2020-12-26T17:33:11Z'"/>
</xsl:variable>
<xsl:variable name="timeZone">
<xsl:value-of select="'America/Los_Angeles'" />
</xsl:variable>
The variable time is in UTC and I would like to convert it to the local timezone. I am using the following but that is not working:
<xsl:value-of select="adjust-dateTime-to-timezone($time), xs:dayTimeDuration($timeZone))"/>
My expected output is: 2020-12-26T09:33:11Z
Upvotes: 0
Views: 869
Reputation: 163322
Nearly all the date/time/timezone functionality in XSLT/XPath is based on absolute numeric timezone offset such as -05:00, not on civil timezones such as CET or America/Los_Angeles. The one exception is format-dateTime(), which is designed to format data for human consumption. The fifth argument to format-dateTime() is "place": XPath 3.1 says:
If the $place argument is supplied in the form of an IANA timezone name that is recognized by the implementation, then the date or time being formatted is adjusted to the timezone offset applicable in that timezone. For example, if the xs:dateTime value 2010-02-15T12:00:00Z is formatted with the $place argument set to America/New_York, then the output will be as if the value 2010-02-15T07:00:00-05:00 had been supplied. This adjustment takes daylight savings time into account where possible; if the date in question falls during daylight savings time in New York, then it is adjusted to timezone offset -PT4H rather than -PT5H. Adjustment using daylight savings time is only possible where the value includes a date, and where the date is within the range covered by the timezone database.
Note that this is new in XPath 3.x; the 2.0 specification only allowed a country code to be used, and was much vaguer about what it meant.
Upvotes: 1