[Bug 1318] New: Comparing durations for equality

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

           Summary: Comparing durations for equality
           Product: XPath / XQuery / XSLT
           Version: Last Call drafts
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Functions and Operators
        AssignedTo: ashok.malhotra@oracle.com
        ReportedBy: mike@saxonica.com
         QAContact: public-qt-comments@w3.org


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

Received on Tuesday, 10 May 2005 10:49:59 UTC