Page 1 of 1

format-dateTime() conventional timezone name

Posted: Mon Feb 23, 2009 5:02 pm
by delirio
I'm trying to get the timezone name using format-dateTime(), following an adjust-dateTime-to-timezone(), in Saxon 9 (whatever version ships with oXygen 10).

with Saxon 8.7 I could do :

declaring xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"

Code: Select all

<xsl:variable name="est-time" select="adjust-dateTime-to-timezone(current-dateTime(), xdt:dayTimeDuration('-PT5H'))"/>
<xsl:value-of selEST="format-dateTime($est-time, '[D] [MN,*-3] [Y] [h]:[m01][PN,*-2] [ZN,*-3]')"/>
The [ZN,*-3] bit would output est.

With Saxon 9 :

declaring xmlns:xs="http://www.w3.org/2001/XMLSchema"

Code: Select all

<xsl:variable name="dateTime" select="current-dateTime()"/>
<xsl:variable name="est-zone" select="xs:dayTimeDuration('-PT5H')"/>
<xsl:variable name="est" select="adjust-dateTime-to-timezone($dateTime, $est-zone)"/>
<xsl:value-of select="format-dateTime($est, '[D] [MN,*-3] [Y] [h01]:[m01] [PN, *-2] [ZN,*-3]')"/>
The [ZN,*-3] bit outputs -05:00.

Re: format-dateTime() conventional timezone name

Posted: Tue Feb 24, 2009 4:47 pm
by delirio
I contacted Saxon support directly and got the reply below, pretty quick too. I guess it'll be useful to someone else having the same problem.
Timezone names vary depending what part of the world you are in. To get the names used in the US, please set the country argument of format-dateTime() to "us", thus:

Code: Select all

format-dateTime($est-time, '[D] [MN,*-3] [Y] [h]:[m01][PN,*-2] [ZN,*-3]', (), (), 'us')

Saxon now also uses the Java database of daylight savings time changes, so if it is known that your date falls within US summer-time, the timezone -05:00 will be displayed as CDT.

Michael Kay
http://www.saxonica.com/

Re: format-dateTime() conventional timezone name

Posted: Tue Feb 24, 2009 5:44 pm
by delirio
further to the above topic . . .
The country parameter should give the location where the event in question took place, it's not the locale of the user of the information. (In fact, timezone formatting is the only thing Saxon uses it for; it was provided primarily for use with non-Gregorian calendars where the translation from Gregorian to another calendar may be location-dependent.)

Timezone -5 never occurs in the UK, and we don't have a name for it; or rather, we call it EST if it happened in New York in winter, CDT if it happened in Chicago in summer, COT if it happened in Colombia, AST if it happened in Brazil, and so on. Hence the need to know where it happened.

Really this is a bit of a mess. The xs:dateTime data type only carries information about UTC offset, not about civil time zone. But format-dateTime requires a civil time zone to be output. So Saxon does its best to guess.

Michael Kay
http://www.saxonica.com/

Re: format-dateTime() conventional timezone name

Posted: Tue Feb 24, 2009 5:53 pm
by sorin_ristache
Thank you delirio for the details.


Regards,
Sorin