Subject: Quarterly appointments

From: Sander Koning <[email-masked]>
Date: Tue, 10 Apr 2007 11:36:45 +0200

Hello,

I'm working on iCalendar import/export for the reservations module in 
our product. So far, everything works quite fine, apart from the fact 
that we support quarterly reservations. For example, "every second 
Tuesday of each quarter" or "every 70th day of each odd quarter".

As iCalendar does not support FREQ=QUARTERLY, I will have to rewrite 
these recurrence rules. Of course I can go and calculate everything 
manually in my code, but that is bound to contain errors. So, if anybody 
has got suggestions about how to tackle this, they would be most welcome.

If this is the wrong list to ask, then a pointer to the right place is 
fine as well, of course.

Thanks in advance,

Cheers,

-- 
Sander Koning
TOPdesk Ontwikkeling

TOPdesk
Martinus Nijhofflaan 2, 2624 ES Delft
Postbus 559, 2600 AN Delft

T  (015) 270 09 00
F  (015) 257 52 56
W  www.topdesk.nl

---

From: "Preston Stephenson" <[email-masked]>
Date: Tue, 10 Apr 2007 11:17:07 -0600

Sorry, its been a while since I've done ICal.
Here is what I did.
RRULE:FREQ=MONTHLY;UNTIL=20080410;INTERVAL=4;BYDAY=2TU

That should work.
Preston

>>> On Tuesday, April 10, 2007 at 3:36 AM, Sander Koning <[email-masked]>

> If this is the wrong list to ask, then a pointer to the right place is 

Novell, Inc.
Software for the Open Enterprise

---

From: "Preston Stephenson" <[email-masked]>
Date: Tue, 10 Apr 2007 11:41:07 -0600

Sorry, I was looking a at a different calendar that was four months wide.
You would do INTERVAL=3 for every 3 months.

Preston

>>> On Tuesday, April 10, 2007 at 11:17 AM, "Preston Stephenson"

Novell, Inc.

---

From: "Mike Samuel" <[email-masked]>
Date: Tue, 10 Apr 2007 13:43:59 -0700

Since the quarters have length (90 || 91), (91), (92), (92), the n-th
day of each quarter is
    BYYEARDAY=$(n),$(-(92+92+91+1-n)),$(-(92+92+1-n)),$(-(92+1-n)),
for n in [1, 90]

You can't do
  FREQ=QUARTERLY;BYDAY=2TU
in a single rule with freq=monthly and interval unless you're sure
that the n-th week falls in the first or last month of the quarter.

You can do it with multiple rrules though
  FREQ=YEARLY;BYMONTH=1,2,3;BYDAY=2TU;BYSETPOS=1
  FREQ=YEARLY;BYMONTH=4,5,6;BYDAY=2TU;BYSETPOS=1
  FREQ=YEARLY;BYMONTH=7,8,9;BYDAY=2TU;BYSETPOS=1
  FREQ=YEARLY;BYMONTH=10,11,12;BYDAY=2TU;BYSETPOS=1

The BYSETPOS should always have magnitude 1 but should have the same
sign as the BYDAY clause.

You can do intervals on quarters by filtering out some of the rules
and/or multiplying the set of rules and applying yearly intervals.

Handling multiple BYDAY clauses is going to require a set of RRULEs
per clause though.