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 2944 - [FO] 10.5 fn:years-from-duration etc have wrong argument types
Summary: [FO] 10.5 fn:years-from-duration etc have wrong argument types
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 Linux
: 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: 2006-02-27 07:39 UTC by Per Bothner
Modified: 2006-04-27 21:41 UTC (History)
0 users

See Also:


Attachments

Description Per Bothner 2006-02-27 07:39:45 UTC
The function fn:years-from-duration is specified to have signature:
  fn:years-from-duration($arg as xdt:yearMonthDuration?) as xs:integer?
This means there is no way to extract the years component
from say xs:duration("P20Y15M10D").

The signature should instead be:
fn:years-from-duration($arg as xs:duration?) as xs:integer?

But you may ask what if the actual argument is an
xs:dayTimeDuration?  In that case the function returns 0.

Likewise for:
fn:months-from-duration
fn:days-from-duration
fn:hours-from-duration
fn:minutes-from-duration
fn:seconds-from-duration
These all should take ($arg as xs:duration?).
Comment 1 Michael Kay 2006-02-27 09:57:32 UTC
It was a conscious decision to design the functions like this. We named them
years-from-duration() etc because the name is shorter and because we thought it
likely that they might be extended one day to cover all durations. But we didn't
want to cover all durations yet, because of difficulties in defining the
semantics. Durations in XML Schema 1.0 are 6-tuples, which would suggest that
years-from-duration(P24M) (excuse the shorthand) should return zero; while in
XML schema 1.1, durations are 2-tuples, which would suggest that the same
function returns 2. 

Michael Kay
(personal response)
Comment 2 Per Bothner 2006-02-27 18:07:09 UTC
(In reply to comment #1)
> Durations in XML Schema 1.0 are 6-tuples, which would suggest that
> years-from-duration(P24M) (excuse the shorthand) should return zero; while in
> XML schema 1.1, durations are 2-tuples, which would suggest that the same
> function returns 2. 

I don't think that's a useful example.  It seems that:
  fn:years-from-duration(xs:duration(LEXVALUE))
should always return the same as
  fn:years-from-duration(xs:yearMonthDuration(LEXVALUE))
whenever xs:yearMonthDuration(LEXVALUE) is well-defined.

The tricky part is when you have a LEXVALUE with components such that it is
neither a yearMonthDuration or a dayTimeDuration.  But even here there it is
well-defined - using the existing definition:
  fn:XXX-from-duration($arg) "Returns an xs:integer[or xs:decimal] representing
the XXX component in the canonical lexical representation of the value of $arg."
That pushes the issue to the "canonical lexical representation" - but that does
appear to handle this case.
(It would probably be cleaner to define "canonical lexical representation" in
terms of fn:XXX-from-duration rather than vice versa, of course) 
Comment 3 Per Bothner 2006-02-27 18:14:43 UTC
(In reply to comment #1)
> Durations in XML Schema 1.0 are 6-tuples, which would suggest that
> years-from-duration(P24M) (excuse the shorthand) should return zero;
> while in XML schema 1.1, durations are 2-tuples, which would suggest
> that the same function returns 2. 

More directly to the point: F&O 10.3.1.3 defines
  fn:years-from-duration(fn:yearMonthDuration("P24M"))
to return 2, not 0.  I.e. F&O already follows the XML schema 1.1 model. 

Comment 4 Andrew Eisenberg 2006-04-27 21:35:03 UTC
This bug report was closed after the WGs made the following decision of May 14, 2006:

Decision: Agree to change function signatures of 6 functions mentioned 
in comments for Bug #2944 to accept duration datatype.

Per, if you agree with this resolution, then please mark this as CLOSED.
Comment 5 Per Bothner 2006-04-27 21:41:37 UTC
Thanks!