Re: fn:format-dateTime without place parameter does not use the system time zone
Michael Kay <[email protected]> Fri, 14 May 2021 15:45:05 +0100
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <[email protected]> |
I think this behaviour matches the spec. The spec 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. By implication, if it is not supplied, no adjustment takes place. The spec also says: If the $place argument is omitted or is set to an empty sequence, then the default place defined in the dynamic context is used. You can set a "default place" using Configuration.setDefaultCountry(), and I think (despite the method name and the Javadoc description) you should be able to set it to "Europe/Berlin" and this should work. But if you haven't set either an explicit place or a default place, it's not going to take it from the system default timezone - the timezone actually present in the dateTime value takes precedence. You can always "lose" the explicit timezone present in the value using adjust-dateTime(), in this case the default timezone will be used. Michael Kay Saxonica > On 14 May 2021, at 14:28, John Ulric <[email protected]> wrote: > > Hello everyone, is it by intention (or by specification) that fn:formatDate does not use the system default time zone if no explicit place parameter is given? > > See this test against current Saxon-HE 10.5: > @Test > public void testTimeZone() throws SaxonApiException { > TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin")); > XPathCompiler compiler = new Processor(Configuration.newConfiguration()).newXPathCompiler(); > assertThat(compiler.evaluateSingle("Q{http://www.w3.org/2005/xpath-functions}format-dateTime(xs:dateTime('2021-05-14T22:00:00Z') <http://www.w3.org/2005/xpath-functions%7Dformat-dateTime(xs:dateTime('2021-05-14T22:00:00Z')>, '[Y0001]-[M01]-[D01] [H01][m01]', (), (), ())", null).getStringValue(), > is("2021-05-14 2200")); > assertThat(compiler.evaluateSingle("Q{http://www.w3.org/2005/xpath-functions}format-dateTime(xs:dateTime('2021-05-14T22:00:00Z') <http://www.w3.org/2005/xpath-functions%7Dformat-dateTime(xs:dateTime('2021-05-14T22:00:00Z')>, '[Y0001]-[M01]-[D01] [H01][m01]', (), (), 'Europe/Berlin')", null).getStringValue(), > is("2021-05-15 0000")); // good! > assertThat(compiler.evaluateSingle("Q{http://www.w3.org/2005/xpath-functions}format-dateTime(xs:dateTime('2021-05-14T18:00:00-04:00') <http://www.w3.org/2005/xpath-functions%7Dformat-dateTime(xs:dateTime('2021-05-14T18:00:00-04:00')>, '[Y0001]-[M01]-[D01] [H01][m01]', (), (), ())", null).getStringValue(), > is("2021-05-14 1800")); > } > Berlin in DST is two hours ahead of GMT. The second assertion with explicit place parameter shows this correctly, displaying the next day 0000 hours. Without a given place, fn:format-dateTime seems to always display the "wall time" as written in the dateTime value, ie, neither in GMT nor in the system time zone, but no time zone at all. > I have also noticed that, while the Configuration class does have settings for the default language and country, and these are automatically initialized from the system defaults, there is no setting for the default time zone. > > John > > _______________________________________________ > saxon-help mailing list archived at http://saxon.markmail.org/ > [email protected] > https://lists.sourceforge.net/lists/listinfo/saxon-help _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ [email protected] https://lists.sourceforge.net/lists/listinfo/saxon-help