This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 1318 - Comparing durations for equality
Summary: Comparing durations for equality
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 1.0 (show other bugs)
Version: Last Call drafts
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: Ashok Malhotra
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-10 10:49 UTC by Michael Kay
Modified: 2005-09-29 10:48 UTC (History)
0 users

See Also:


Attachments

Description Michael Kay 2005-05-10 10:49:52 UTC
ACTION: A-252-01 - Michael Kay will file a separate LC comment on "Specify an
equality comparison for xs:duration values" and proposing a comparison
mechanism.  Bug 1208 should be dependent on the new bug, and when we resolve the
new bug we will revisit 1208.

We should define an equality comparison for xs:duration values.

(a) There's no good reason not to. Although ordering of durations is
problematical, there's no problem defining equality. Admittedly there is more
than one possible definition, but that's true of many of our data types.

(b) Not having an equality operation for durations causes implementation
difficulties with other operations such as distinct-values(), deep-equal(), and
(in XSLT) sorting and grouping. For example, distinct-values() treats all
durations as distinct from each other, which makes it hard to come up with a
suitable hashing function; similarly, deep-equal() has to search a document to
arbitrary depth, because if it contains a duration anywhere then it is not
deep-equal to any other document, not even itself.

The proposed definition is that two durations $d1 and $d2 are equal if and only
if xdt:dayTimeDuration($d1) eq xdt:dayTimeDuration($d2) and
xdt:yearMonthDuration($d1) eq xdt:yearMonthDuration($d2).

To implement this:

(a) in the language books, add two lines to the operator mapping table in B.2:

A eq B | xs:duration | xs:duration | op:duration-equal(A, B) | xs:boolean
A ne B | xs:duration | xs:duration | fn:not(op:duration-equal(A, B)) | xs:boolean

(b) Add a new function to F+O:

10.4.x op:duration-equal

op:duration-equal( $arg1 as xs:duration,
                   $arg2 as xs:duration) as xs:boolean

Summary: Returns true if and only if $arg1 is equal to $arg2. Returns false
otherwise.

This function backs up the "eq" and "ne" operators on xs:duration values.

The function returns true if xdt:dayTimeDuration($arg1) eq
xdt:dayTimeDuration($arg2) and xdt:yearMonthDuration($arg1) eq
xdt:yearMonthDuration($arg2); otherwise it return false.

Examples:

xs:duration("P1Y") eq xs:duration("P12M") returns true.
xs:duration("PT24H") eq xs:duration("P1D") returns true.
xs:duration("P1Y") eq xs:duration("P365D") returns false. 


Michael Kay
Comment 1 Michael Kay 2005-05-10 10:55:51 UTC
In F+O, Appendix D.6 should also be removed, as should the paragraph in 10.2 "No
operators are defined on the [XML Schema Part 2: Datatypes Second Edition]
datatype xs:duration. Appendix D.6 Working With xs:duration Values discusses how
to work with xs:duration values.". 

In 10.4, change "For this reason, no functions are defined on xs:duration." to
"For this reason, no ordering functions are defined on xs:duration."
Comment 2 Ashok Malhotra 2005-05-31 16:34:46 UTC
The joint WGs agreed to add the operator op:duration-equal and make the changes
suggested by Michael Kay in the comments attached to this note to the F&O and
the language book.  See minutes on joint WG meeting 5-16-2005.

Ashok Malhotra