Subject: Re: Can we fix BYSETPOS?

From: [email-masked]
Date: Wed, 20 Jun 2001 16:38:43 -0400

Jonathan Lennox <[email-masked]> wrote on 06/20/2001 02:02:49 PM:
>[We're discussing
>       RRULE:DTSTART;TZID=US-Eastern:20010406T090000
>       RECUR:FREQ=WEEKLY;BYMONTH=4;BYSETPOS=1
>]
[Snip, snip]
> > If you follow the decoding guidelines in Section 4.3.10 (p. 44 
generally) 
> > then you decode the RRULE in the following way:
> > 
> > 1: There is an implicit "INTERVAL=1" defined so this rule starts as 
"Every 
> > week" (or "Every week in the year forever" if you want a more verbose 
> > description")
> > 2: "BYMONTH=4" refines it down to "Every week in April (forever)"
> 
> > 3: "BYSETPOS=1" refines it to "The first instance of the set of 
> > dates("Every week in April (forever)")"
> 
> Step 3 is the step I don't get, and it's where the definition of "set" 
is
> crucial.

I sure wish that Frank or Vinod would pipe up for a change so that they 
can help Jonathan understand this.  I don't seem to be doing a bang up job 
of it.  I cannot give a purely mathematical defintion so Ive tried to 
define by example (something I think I picked up from Frank along the 
way).

I think that before now there was some believe that the 'set' was all 
possible instances ever (which makes BYSETPOS=-1 impossible for infinitely 
repeating sets like our current example).

Ill try another description to see if I can clarify it while I poke the 
others OOB to provide an answer that may help you further.  In Step #2 we 
have a set or 'template' (new term to try and get around any mental 
baggage) for the rule that contains "Every week in April (forever)".  That 
is, it contains:

1: The (effective) DTSTART date/time (call it DTS0).  In reality it is 20010406T090000.
2: DTS0 + "1 week" (DTS1).  In reality it is 20010413T090000.
3: DTS1 + "1 week" (DTS2).  In reality it is 20010420T090000.
4: DTS2 + "1 week" (DTS3).  In reality it is 20010427T090000.

There is no #5 since DTS3 + "1 week" would put it outside the BYMONTH 
value for 2001 but it MAY exist eventually in some years. 

The template does NOT contain 20020405T090000, 20020412T090000, etc. since 
that would be another Aprils worth of values and that would require 
evaluating the subcomponents again (ie: another pass down the evaluation 
order).  We do not do this since that is basically reevaluating the rule 
at its next starting point using a the BYMONTH over again. 

This is probably going to be confusing or disputable to some at this point 
but Ill press on to try and complete my description.

So when we get to Step #3 we want to take just the 1st instance of the 
template (ie: Just item #1) and that is how I got to my dates I originally 
posted.

> Clearly, "the set of dates consisting of the first instance of the set 
of
> dates 'Every week in April, forever'" has exactly one member - one day 
in
> April.

If you describe it that way then it does have only 1 value (the DTSTART 
really).  However I think that the 'forever' tidbit is confusing the 
matter.  I only put it in to be complete since we never had an UNTIL or 
COUNT.

However I do not read Step #3 as "the set of dates consisting of the first instance of the set of dates 
'Every week in April, forever'"  I read it as "the set of dates consisting of the first instance of the set of dates 
'Every week in April' that repeats forever".  Perhaps I should have written my original text better but I did not 
mean to say that the BYSETPOS evaluation applied to an infinite set but it 
repeated infinitely on the set of "Every week in April". 

If you take the view that the BYSETPOS applies to all possible instances 
of a rule then you are not limited by 31M but rather by infinity and that 
is just not even remotely viable no matter how long you apply Moores law.

Perhaps it would help me understand your confusion if you could decypher 
the following example:

DTSTART;TZID=US-Eastern:20010621T090000
RRULE:FREQ=MONTHLY;BYDAY=TH;BYSETPOS=4

for me.  Do you view it as "The 4th Thursday in the month, forever"?  Or 
"The set of dates consisting of the 4th instance of the set of dates 
'Every Thursday in the month, forever'"? Or "The set of dates consisting 
of the 4th instance of the set of dates "Every Thursday in the month", 
forever"?  The differences are subtle but significant.

> Similarly, "the set of dates consisting of the last instance of the set 
of
> dates 'Every week in April, forever'" is ill-defined, as there is no 
such
> last instance -- the set continues (as it says) forever.

Poor grammar on my part attempting to mimic the style of 2445.  I think it 
is better written as "the set of dates consisting of the last instance of the set of dates 
'Every week in April', forever" (the single quote was moved to not include 
the last word).

> So you're implicitly assuming some other algorithm for determining the
> meaning of BYSETPOS, presumably derived from whatever algorithm you're 
using
> to enumerate infinite sets.

Will not go down that path as it was NEVER my contention that the set / 
template was infinite in size.  I was pointing out that if you applied 
BYSETPOS incorrectly you could mistakenly create a single, infinite set 
rather than a set of instances (or a single instance) that is repeatedly 
reused forever.

> If I decided to use an algorithm of "expand the set so that all events 
are a
> constant-time offset from n * constant-period + DTSTART", my sets for 
the
> above rule would be twenty-eight years in length (ignoring the Gregorian
> correction and any year-dependent changes in time zone rules).

I think you shorted something in your calculation.  You could never have 
the full set since you did not include a COUNT or UNTIL so the set of 
matching dates becomes infinite (assuming we dont split hairs about the 
value becoming Y10K, etc).

> The standardized meaning Eric and I came up with was that the enclosing 
set
> was the unit of time indicated by FREQ.  This is a natural fit with the
> second algorithm I said above, and is easy to explain and to understand.
> However, this clearly isn't what you're doing.  So I don't understand 
what
> you *are* doing.
> Can you explain it? 

Ill get the person who owns it now to describe it in an attempt to get 
another voice involved.  That may help clarify things.

Bruce
PS: I know the cited example @ the top is off but its readers can 
understand it all the same... Do not send me nudges OOB about it.
===========================================================================
Bruce Kahn                                INet: [email-masked]
Iris Associates                          Phone: 978.392.5335
Westford, MA, USA 01886                    FAX: and nothing but the FAX...
Standard disclaimers apply, even where prohibited by law...

---

From: Jonathan Lennox <[email-masked]>
Date: Wed, 20 Jun 2001 17:08:41 -0400 (EDT)

> repeating sets like our current example).

Yes, clearly that's wrong.  That was mostly just a complaint about the
terminology being unclear.  I didn't mean to harp on that point.

I think it's also clear that even for bounded sets, COUNT and UNTIL apply
*after* BYSETPOS.

> at its next starting point using a the BYMONTH over again. 

So you're saying that the duration of the 'template' depends on the largest
BY* rule (or FREQ, if that's larger) mentioned in the rule.

I really don't like that -- I think the interpretation which I, Eric, and
Robert advocate is both much more useful and much easier to explain.

Here's why.  Consider the following three rules:

       RRULE:DTSTART;TZID=US-Eastern:20010401T090000
       RECUR:FREQ=WEEKLY;BYMONTH=4,6;BYDAY=FR;BYSETPOS=-1

       RRULE:DTSTART;TZID=US-Eastern:20010401T090000
       RECUR:FREQ=MONTHLY;BYMONTH=4,6;BYDAY=FR;BYSETPOS=-1

       RRULE:DTSTART;TZID=US-Eastern:20010401T090000
       RECUR:FREQ=YEARLY;BYMONTH=4,6;BYDAY=FR;BYSETPOS=-1

As far as I can generalize from your example, these three examples under
your interpretation would be *identical* -- the FREQ is completely
irrelevant.  They all generate "The last Friday of (April or June)".

Under my interpretation, these would be, respectively, "the last Friday of
the week, in April and June" (i.e. "Fridays in April and June"); "the last
Friday of April, and the last Friday of June"; and "the last Friday of
(April or June)" (i.e., given DTSTART, "The last Friday of June").

Regardless of what RFC 2445 seems to say (and I think it's apparent by now
that this is terribly unclear), do people agree that the above
interpretation is what RRULE *should* mean?

-- 
Jonathan Lennox
[email-masked]

---

From: Damon Chaplin <[email-masked]>
Date: Thu, 21 Jun 2001 00:34:03 -0400

> interpretation is what RRULE *should* mean?

I think (hope/pray!) you are correct on this.

I think the set covers a period equal to the RRULE frequency.
e.g. for "FREQ=WEEKLY" a set of occurrences is generated for each week.
for "FREQ=YEARLY;INTERVAL=2" a set of occurrences is generated for every other year.

Damon