This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
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?).
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)
(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)
(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.
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.
Thanks!