Re: Functions on Dates, Times and Durations

Let's re-visit the topics that I raised in
http://lists.w3.org/Archives/Public/public-qt-comments/2003Dec/0261.html,
then garbage-collect Topic 1 and add a new Topic 3.

Topic 1: Don't process durations without a reference
dateTime
-------------------------------------------------------------

Jim wrote in
http://lists.w3.org/Archives/Public/public-qt-comments/2003Dec/0268.html

>>Are there really worthwile use cases that require
>>duration processing without a dateTime to relate to?
>
>Well, that depends on whose definition of
"worthwhile" you're using.
>
>Most people involved in, say, the food industry
>would think that the duration of
>"1 hour 30 minutes" would be important
>without regard to a specific dateTime,
>as in "cook at 200°C for 1 hour 30 minutes".
>Similarly, a courier service whose business
>depends on their guarantee that "we'll
>deliver anywhere in the same country
>within 18 hours" would certainly like
>to be able to prove the truth of that
>statement automatically (which means
>they need to represent it in their original
>XML documents).

You are right, indeed. Therefore, I take back
my provocative claim. I agree that durations
can make sense also without a dateTime,
particularly the drafted subclass xdt:dayTimeDuration
does.

Myself, I wrote in
http://lists.w3.org/Archives/Public/public-qt-comments/2003Dec/0261.html
>For example, if you have a reference_dateTime,
>then it is easy to compare. You just compare
>dateTimes:
>
>reference_dateTime + duration_1 < reference_dateTime
+ duration_2

Reading
http://lists.xml.org/archives/xml-dev/200209/msg01169.html,
I found that my idea to compare durations
on the basis of a reference dateTime
does not work in general, either.
This is linked to the day pinning algorithm
specified in XML Schema Part 2.
Unfortunately, there seems no way to do a better job.
See the mental search for a good algorithm in
http://lists.xml.org/archives/xml-dev/200209/msg01183.html.

Jim wrote in
http://lists.w3.org/Archives/Public/public-qt-comments/2003Dec/0268.html
>Sorry to be so strong in my disagreement,
>but I do feel very strongly that 
>durations exist, and should be manipulable,
>in the absence of specific dateTimes.

Your disagreement was completely in order.
While it may well be that general xs:duration values
are undesirable without a dateTime, certainly the
logical concept of a duration cannot be questioned
and I take that back.

So, durations or at least some of its subclasses are
a useful type. Once we have a type, powerful
operations
should be available for it. This brings me to
re-visiting topic 2:

Topic 2: There should be a function to add dateTime +
duration
--------------------------------------------------------------

Xavier wrote in
http://lists.w3.org/Archives/Public/public-qt-comments/2003Dec/0269.html
>Then a sane approach of the question should be
>to avoid manipulating xs:duration
>as much as possible and to perform
>all computations with numeric durations in seconds.

The correct observation that some operations
with xs:duration are problematic
cannot justify a complete ban on xs:duration
arithmetic also in cases, where the arithmetic
does make sense and is easy to grasp.
Most prominently, adding an xs:duration
to an xs:dateTime is meaningful.
(Though you have to specify whether you first add
the yearMonth part or the dayTime part.)

A function
date:add-dateTime-duration(xs:dateTime,xs:duration)
would replace two functions
op:add-dayTimeDuration-to-dateTime
and op:add-yearMonthDuration-to-dateTime.
Similar simplifications of the API are thinkable
for substraction, too.

This may not be a big simplification,
but I think people have an expectation
that such a function should be there.
Not without a reason, the addition
xs:dateTime+xs:duration is specified
in XML Schema and also in the EXSLT package.
It is possible and has not too many surprises
(the only one I think of is the panning behaviour,
but this is also problematic
when adding xdt:yearMonthDuration values).

I think that, if we do not want
to undermine xs:duration as such,
we should not make it unnecessarily
difficult to process.

A method fn:subtract-dateTimes-yielding-duration
would also be possible, and it is there in EXSLT.
The resulting duration would naturally relate
to the first argument of the function.

Topic 3: Use of normalized value in
add-yearMonthDuration-to-dateTime
---------------------------------------------------------------------

I have a doubt about
http://www.w3.org/TR/2003/WD-xpath-functions-20031112/#func-add-yearMonthDuration-to-dateTime.

It says here that the first argument internally is
normalised first and then the addition happens.
I feel that this treatment of timezones may
yield strange results close to a change of month.

Example: Consider the sum expression

2001-03-01T06:00:00 + P1M.

Who would not agree that the expected result
is 2001-04-01T06:00:00?

First assume I am living in London at timezone 0:00.
So normalisation has no role and there are
no other problems, so the result would be

2001-04-01T06:00:00,

which indeed matches my expectations.

Next assume that I am living in Beijing
with UTC plus 8 hours, and consider
the same sum expression

2001-03-01T06:00:00 + P1M.

The normalisation away from the default timezone to Z
then implies interpretation of my sum expression as

2001-02-28T22:00:00Z + P1M,

because it was still late evening in London,
when it was already early morning in Beijing.
After the addition of P1M I get

2001-03-28T22:00:00Z

and thus, back in Beijing local time zone,

2001-03-29T06:00:00

So in Beijing, I get
2001-03-01T06:00:00 + P1M = 2001-03-29T06:00:00.

Note that the problem is not the use of a default
timezone. I have the same trouble when specifying
zone +8:00:

2001-03-01T06:00:00+8:00 + P1M =
2001-03-29T06:00:00+8:00.

I have the feeling that this is wrong.
But it may be intended in the end. Any views?

Cheers,

Bernhard


Further references:

Duration algebra:
http://www.w3.org/TR/2003/WD-xpath-functions-20031112/#durations-dates-times
http://www.w3.org/TR/2003/WD-xpath-functions-20031112/#dateTime-arithmetic
http://www.w3.org/TR/xmlschema-2/#adding-durations-to-dateTimes
http://www.w3.org/TR/xmlschema-2/#adding-durations-to-instants-commutativity-associativity

Ordering durations:
http://lists.xml.org/archives/xml-dev/200209/msg01116.html
http://lists.xml.org/archives/xml-dev/200209/msg01160.html

EXSLT:
http://www.exslt.org/date/functions/add/date.add.html
http://www.exslt.org/date/functions/add-duration/date.add-duration.html
http://www.exslt.org/date/functions/difference/date.difference.html
http://lists.xml.org/archives/xml-dev/200209/msg01158.html

Timezone issues:
http://lists.xml.org/archives/xml-dev/200209/msg01156.html

--- END ---



________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" 
your friends today! Download Messenger Now 
http://uk.messenger.yahoo.com/download/index.html

Received on Monday, 22 December 2003 12:36:54 UTC