Hi Harri,

https://www.w3.org/TR/xpath-functions-3/#func-subtract-dates

The difference of two dates is the duration bwteeen the dates as points on the timeline as a xs:dayTimeDuration.

?age is "P14484DT0H0M0.000S"^^xsd:dayTimeDuration

not PnnYnnMnnD

A duration is a defined, fixed length of time.


There two kinds of durations xs:dayTimeDuration and xs:yearMonthDuration
https://www.w3.org/TR/xpath-functions-3/#duration-subtypes

where arithmetic and ordering can be meaningfully defined at all.

A combination of months and days is not a fixed interval of time because the number of days in a month isn't the same for all months.

Only xs:dayTimeDuration defines a duration that is of a well-defined difference of two points on the timeline (ignoring negative leap seconds).

Once "xsd:date - xsd:date" is calculated, the duration is a fixed length of time and does not tie back to which dates were used in the calculation.

So "P14484D.." is right not "P44Y6m??D"

[[
Confusingly the difference of two Gregorian year-months (gYearMonth) is also an xs:dayTimeDuration, and not a xs:yearMonthDuration, not that it is really defined on gYearMonth (section 9.1), because gYearMonth maps to a point on the timeline and the difference is of two points on the timeline.
]]


With ?age is "P14484DT0H0M0.000S"^^xsd:dayTimeDuration

For the casting to xsd:yearMonthDuration: (had to check this one!)

Casting xsd:dayTimeDuration to xsd:yearMonthDuration is defined.

https://www.w3.org/TR/xpath-functions-31/#casting-from-primitive-to-primitive

https://www.w3.org/TR/xpath-functions-31/#casting-to-durations
"""
If ST is xs:yearMonthDuration and TT is xs:dayTimeDuration, the cast is permitted and returns a xs:dayTimeDuration with value 0.0 seconds.
"""
ST is "source type" TT is target type".

I don't know the rationale - (a guess - treat like it is selecting fields from PnnYnnMnnDT..)

    Andy


On 27/01/2021 17:16, Harri Kiiskinen wrote:
Dear all,

This example run with Fuseki 3.17:

--------------------------------------------------------------------
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?y ?d (xsd:dayTimeDuration(?age) as ?a1)
              (xsd:yearMonthDuration(?age) as ?a2)
where {
   bind ( xsd:date("1984-12-01") as ?y)
   bind ( xsd:date("1944-05-06") as ?d)
   bind ((?y-?d) as ?age )
}
-------------------------------------------------------------------

Gives unexpected results:

------------------------------------------------------------------
y,d,a1,a2
1984-12-01,1944-05-06,P14484DT0H0M0.000S,P0M
------------------------------------------------------------------

I was expecting the variable "a2" to contain the duration expressed in Years and Months, but instead it is zero.


What am I doing wrong here?

Best,

Harri Kiiskinen

Reply via email to