Project

Profile

Help

fn:adjust-dateTime-to-timezone and DST

Added by Anonymous over 13 years ago

Legacy ID: #10314250 Legacy Poster: Nick Van den Bleeken (nvdbleek42)

I have a question related to adjust-dateTime-to-timezone, dateTime calculation and DST. I'm not sure if my 'problem' is caused by Saxon or the XPath specifications. Here is my use case: * A user entered a data and time without time zone information because it is in his local timezone (e.g.: 2011-06-16T15:00:00) * I want to add 6 months to the dateTime ( xs:dateTime('2011-06-16T15:00:00') + xs:yearMonthDuration('P6M') ) * Now I want to store the data including the timezone information so I use fn:adjust-dateTime-to-timezone which results in 2011-06-16T15:00:00 + 6M : 2011-12-16T15:00:00+02:00 -> We are currently in DST (summer time), but in december we will be in winter time => the dateTime is one hour off what the user would expect, because in winter we aren't in +02:00 but in +01:00 If I read the spec I'm not sure what fn:adjust-dateTime-to-timezone has to do (it possibly gives a hint that the offset is fixed and not depend on the actual date). So my question is, is Saxon conform the specification, or is this something that wasn't taken into account when implementing the function? (To recap: adjust-dateTime-to-timezone(xs:dateTime('2011-06-16T15:00:00') + xs:yearMonthDuration('P6M')) doesn't returns the dateTime in the users timezone on that actual point in time.) Thanks in advance, Nick Van den Bleeken


Replies (3)

Please register to reply

RE: fn:adjust-dateTime-to-timezone and DST - Added by Anonymous over 13 years ago

Legacy ID: #10314572 Legacy Poster: Michael Kay (mhkay)

This is really a question about the specs, not about Saxon. I think you will find that Saxon does what the specs say. Essentially, the dateTime data types understand time offsets, but not timezones. (They talk about timezones, but it's a misnomer). If you have a dateTime with an explicit time offset, then arithmetic operations will result in another dateTime with the same offset. If you use a dateTime with no time offset, then the implicit offset is based on the difference between your wall clock and GMT at the time you run the query. To help you get around these problems, Saxon provides the function saxon:adjust-to-civil-time() http://www.saxonica.com/documentation/extensions/functions/adjusttociviltime.xml If you apply this function to the result of your time computation, specifying "Europe/Brussels" as the time zone name, you should get what you consider the "intuitive" answer.

RE: fn:adjust-dateTime-to-timezone and DST - Added by Anonymous over 13 years ago

Legacy ID: #10316746 Legacy Poster: Nick Van den Bleeken (nvdbleek42)

Thank you for the fast reply and sorry fo posting it to the wrong forum/list. I understand that xs:dateTime doesn't supports 'time zones' but only offsets to UTC. Also saxon:adjust-to-civil-time() helps me in determining the UTC offset in a particular timezone at a particular date. But as I see it it doesn't helps much when doing calculations (I could extract the offset component of both dates and compensate based on the difference, but this feels like a hack). I also realize that that if fn:adjust-dateTime-to-timezone() will use time zone information instead of current UTC offset this will only solve my 'problem' when offset component is provided in the xs:dateTime. But if it would work like this it at least solves the local time part of the 'problem'. As a side note XForms also has a version adjust-dateTime-to-timezone() (in the next version all xforms extension functions will be in the xforms NS) and for that function we recently decided to issue an erratum that adjust-dateTime-to-timezone() should take into account local time zone information and not local UTC offset at this moment. Do you think that it is worth sending a message to the XSL mailing list explaining the problem with dateTime calculation in combination with DST? Thanks in Advance, Nick Van den Bleeken

RE: fn:adjust-dateTime-to-timezone and DST - Added by Anonymous over 13 years ago

Legacy ID: #10316998 Legacy Poster: Michael Kay (mhkay)

I think you should probably take this up with the XSL/XQuery WGs. It's a known problem, though I'm not sure there is a will to solve it. Many of us went through the period when we were debating whether 29 Feb 2004 plus one year is 28 Feb 2005 or 1 Mar 2005, and know that we will never get an answer that everyone agrees on; handling civil time zones can only multiply such problems, and many would argue that this should be in an application-level function library.

    (1-3/3)

    Please register to reply