RE: [F&O] IBM-FO-106: fn:subtract-dateTimes-yielding-yearMonthDuration - "maximum number of months" is imprecise

This note was rubbish - I forgot which function we were talking about. 

But something like the following seems to work:

(a) Remove the day/hour/minute/second components of both arguments, leaving
only a year and a month. Call these (Y1, M1) for the first argument and (Y2,
M2) for the second argument

(b) If the day/hour/minute/second part of the second argument was greater
than the day/hour/minute/second part of the first argument, add one to M2.

(c) if (Y1<0) then Y1 := Y1 + 1

    if (Y2<0) then Y2 := Y2 + 1

    (this is because XML Schema gets negative dates wrong)

(d) The answer is the duration x months where x is (12*(Y1-Y2) + M1-M2)

(This rule gives the difference between 2004-02-28 and 2004-01-31 as 0
months rather than one month, which feels right to me, though it's a matter
of opinion).

Michael Kay
 

> -----Original Message-----
> From: public-qt-comments-request@w3.org 
> [mailto:public-qt-comments-request@w3.org] On Behalf Of Michael Kay
> Sent: 30 March 2004 08:33
> To: 'Ashok Malhotra'; 'Henry Zongaro'; public-qt-comments@w3.org
> Subject: RE: [F&O] IBM-FO-106: 
> fn:subtract-dateTimes-yielding-yearMonthDuration - "maximum 
> number of months" is imprecise
> 
> 
> > Henry:
> > I realized after I sent the note that we needed to be more 
> > precise about
> > the wording and we should discuss the details.  I'll put it on the
> > agenda.
> > 
> > Here is my proposal:
> > You start with $arg2 and count towards $arg1.
> > Keeping the day and time values constant you increment the 
> > month value,
> > rolling over the year value as needed until adding another 
> month would
> > take you past $arg1.  You then convert the months you added into an
> > yearMonthDuration.
> > 
> > Make sense?
> > 
> 
> Your proposed text doesn't explain what happens with negative 
> durations.
> 
> I actually thought the wording in the Christmas Day draft was 
> an improvement
> over the 12 Nov wording, and was probably OK.
> 
> But here's a more precise approach:
> 
> Firstly, calculate the number of months M1 between the supplied
> date/dateTime and the baseline xs:date -0001-01-01 
> (equivalent to the ISO
> 8601 date 0000-01-01). If the year is positive, this is (12*y 
> + m-1) where y
> and m are the year and month components of the date. If the year is
> negative, M1 is the negative number (12*(y+1) + (12-m)).
> 
> Now calculate the number of months M2 in the supplied 
> duration, as 12*y+m
> where y and m are the year and month components of the 
> duration. (If the
> duration is negative, both y and m are negative).
> 
> Finally, add the number of months (M1+M2) to the baseline xs:date
> -0001-01-01, using the rules for adding a yearMonthDuration to a date.
> 
> Michael Kay   
> 
> 
> 

Received on Tuesday, 30 March 2004 08:19:50 UTC