[Bug 4856] [F&O] arithmetic on durations

http://www.w3.org/Bugs/Public/show_bug.cgi?id=4856


Benjamin Nguyen <benjie.nguyen@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |benjie.nguyen@gmail.com




--- Comment #10 from Benjamin Nguyen <benjie.nguyen@gmail.com>  2008-09-12 13:39:31 ---

After checking ISO 8601:2004 [1], duration are indeed defined as non-negative : 

"duration
non-negative quantity attributed to a time interval, the value of which is
equal to the difference between the
time points of the final instant and the initial instant of the time interval,
when the time points are quantitative
marks"

XML-Schema [2] allows negative intervals : "One could also indicate a duration
of minus 120 days as: -P120D."
This does not seem to be allowed by ISO.

However, XML-Schema does not allow partial negative values inside a duration
i.e., "P1Y-1D" in order to indicate "a year minus a day" is forbidden.
Note that this is explicitly forbidden, since the values representing years,
months, days, etc. are defined as unsigned integers (3.2.6.1)
Also note that in Functions and Operators [3] it is indicated in 10.2 that the
values are xs:integers (xs:decimal for the seconds but this is not important)

A simple proposal (although conflicting with ISO 8601) would be to *allow*
negative values to the subparts of a duration, i.e., "P1Y-1M" would be accepted
as valid.
In this case, it would directly be possible to use the algebra as proposed by
Mike Kay by decomposing a duration into a xs:yearMonthDuration part (with + and
- operators) and a xs:dayTimeDuration (with + and - operators)
We suggest in fact allowing only negative values for the xs:yearMonthDuration
and/or xs:dayTimeDuration parts, i.e., "P1Y-1M" would not be acceptable, since
"P1Y-1M" = "P11M" but "P1Y-1D" would be, since it is in fact "P1Y" + "-P1D"

Let us also stress that in principle, according to ISO-8601 a duration can only
occur in the following contexts :
"
a) by a start and an end;
b) by a duration and context information;
c) by a start and a duration;
d) by a duration and an end.
"

The only delicate case is case b) since it is the only case where "P1Y-1D" can
be ambiguous : it would not evaluate to the same value in xs:dayTimeDuration if
added to 2000-01-01T00:00:00Z or 1999-01-01T00:00:00Z
In the first case it is 365 days, in the latter 364, but again "context
information" means that in both cases "P1Y-1D" makes sense.

Regards,

Benjamin Nguyen & Tristan Allard


[1] ISO 8601:2004,
http://isotc.iso.org/livelink/livelink/4021199/ISO_8601_2004_E.zip?func=doc.Fetch&nodeid=4021199
[2] XML Schema : Datatypes, http://www.w3.org/TR/xmlschema-2/
[3] XQuery functions and Operators, http://www.w3.org/TR/xpath-functions/


-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Friday, 12 September 2008 13:40:11 UTC