On 06/12/13 16:09, Alexander Dutton wrote:
Hi Ewa,

On 06/12/13 16:03, Ewa Szwed wrote:
Got it!
Done:

*    BIND(str(floor(fn:days-from-duration(?date_of_death - ?date_of_birth)
/ 365)) as ?age_at_death)*

Careful; that'll only get you the days component¹. Even if it did what
you were hoping for, you'll end up with off-by-one errors if they die
close to their birthday due to the cumulative effects of leap years.

You probably want:

BIND(fn:years-from-duration(?date_of_death - ?date_of_birth) AS
?age_at_death)

You are right to worry.

There are two kinds of (totally order) durations:

xsd:yearMonthDuration
xsd:dayTimeDuration

you can't mix them (months have variable number of days)

The difference of two xsd:dates is a number of day so the duration is of the dayTimeDuration which does not have a year component.

fn:years-from-duration is an accessor - it's not calculating the number of years because it can't as without a timeframe, you don't know about leap years.

So ?date_of_death - ?date_of_birth is a number of days and /365 is about the best estimate you can do without grounds the calculation in a fixed timeframe.

I may have got this wrong, but in implementation ARQ converts to milliseconds and then uses Java's newDuration(long milliSeconds) which returns a large day component xsd:Duration, no years or months.

        Andy


Best regards,

Alex

¹ <http://www.w3.org/TR/xpath-functions/#func-days-from-duration>


Reply via email to