Creating rule to eliminate weekend and holidays.

214 views
Skip to first unread message

Steve

unread,
Apr 28, 2010, 10:03:14 AM4/28/10
to google-rfc-2445
Hello,
I'm trying to build the formula for eliminate weekends and holidays
from my ical return list. My requirement example is as follows:

On 15th of each month, for 12 Occurances - but do not use weekends.

results: when start date is 15 April 2010


RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=15;BYDAY=MO,TU,WE,TH,FR;COUNT=12

mydate: 2010-04-15
mydate: 2010-06-15
mydate: 2010-07-15
mydate: 2010-09-15
mydate: 2010-10-15
mydate: 2010-11-15
mydate: 2010-12-15
mydate: 2011-02-15
mydate: 2011-03-15
mydate: 2011-04-15
mydate: 2011-06-15
mydate: 2011-07-15

I return 12 valid dates, but it skips 15 May 2010 because it is on a
Saturday. But what I need it to do is return back one day 14 May
2010. Is this possible or do I need to take the date return and do
the checking myself? Any assistance would be greatly apprecieated.

Steve

--
You received this message because you are subscribed to the Google Groups "google-rfc-2445" group.
To post to this group, send email to google-...@googlegroups.com.
To unsubscribe from this group, send email to google-rfc-24...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-rfc-2445?hl=en.

Mike Samuel

unread,
Apr 28, 2010, 11:20:07 AM4/28/10
to google-...@googlegroups.com
RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=15,16,17;BYDAY=MO,TU,WE,TH,FR;COUNT=12;BYSETPOS=1
?

2010/4/28 Steve <steve_...@verizon.net>:

Mike Samuel

unread,
Apr 28, 2010, 11:40:41 AM4/28/10
to google-...@googlegroups.com
Sorry, you want to jump back not forward, so

RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=13,14,15;BYDAY=MO,TU,WE,TH,FR;COUNT=12;BYSETPOS=-1

What this rule is saying is every (interval) month (freq) for 12
(count) months (freq) return the last day (bysetpos=-1) that both
falls on the 13th, 14th, or 15th of the month (bymonthday) and that
falls on a weekday (byday).



2010/4/28 Mike Samuel <mikes...@gmail.com>:

Steve

unread,
Apr 28, 2010, 11:56:42 AM4/28/10
to google-rfc-2445
Thanks. Mike, that worked out wonderfully. Now I understand the
bysetpos better. Now does the RRULE have anything for holidays
(yearly). I have not seen anything within the code, but thought I
would ask.

Regards.

Steve

On Apr 28, 11:40 am, Mike Samuel <mikesam...@gmail.com> wrote:
> Sorry, you want to jump back not forward, so
>
> RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=13,14,15;BYDAY=MO,TU,WE,TH,FR;COUN­T=12;BYSETPOS=-1
>
> What this rule is saying is every (interval) month (freq) for 12
> (count) months (freq) return the last day (bysetpos=-1) that both
> falls on the 13th, 14th, or 15th of the month (bymonthday) and that
> falls on a weekday (byday).
>
> 2010/4/28 Mike Samuel <mikesam...@gmail.com>:
>
>
>
>
>
> > RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=15,16,17;BYDAY=MO,TU,WE,TH,FR;COUN­T=12;BYSETPOS=1
> > ?
>
> > 2010/4/28 Steve <steve_nor...@verizon.net>:
> >> For more options, visit this group athttp://groups.google.com/group/google-rfc-2445?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "google-rfc-2445" group.
> To post to this group, send email to google-...@googlegroups.com.
> To unsubscribe from this group, send email to google-rfc-24...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/google-rfc-2445?hl=en.- Hide quoted text -
>
> - Show quoted text -

Mike Samuel

unread,
Apr 28, 2010, 1:47:53 PM4/28/10
to google-...@googlegroups.com
Some holidays are easy:
New Year's: RRULE:FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1
some are harder: US election day is the Tuesday after the first Monday
of November in even-numbered years which can be represented as
RRULE:FREQ=YEARLY;INTERVAL=2;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8
but require some thinking to puzzle out; and some are quite difficult,
e.g. Easter in some traditions is the first Sunday after the full
moon.
Like Easter, anything based on lunar calendars (most Arabic, Chinese,
and Hebrew holidays) or Egyptian/Ethiopian/Coptic calendars just don't
fit into the Gregorian calendar.

cheers,
mike

2010/4/28 Steve <steve_...@verizon.net>:

Steve

unread,
Apr 28, 2010, 5:01:22 PM4/28/10
to google-rfc-2445
Mike,

Thanks for the help on the holidays, I think I will manage that
myself. I did more testing on the weekday rule you gave me and it
works great except when my date is on the 1st and 2nd of the month.

So if I would like to create a calendar entry for the 1st day of
every month for 4 occurences but NOT on weekends I used, but the dates
are not correct.

RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=30,31,1;BYDAY=MO,TU,WE,TH,FR;COUNT=4;BYSETPOS=-1
mydate: 2010-04-01 Thu - Correct
mydate: 2010-04-30 Fri - Correct
mydate: 2010-05-31 Mon - Incorrect should be 2010-06-01 Tue
mydate: 2010-06-30 Wed - Incorrect should be 2010-07-01 Thu

Thanks for your help.

On Apr 28, 1:47 pm, Mike Samuel <mikesam...@gmail.com> wrote:
> Some holidays are easy:
>     New Year's: RRULE:FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1
> some are harder: US election day is the Tuesday after the first Monday
> of November in even-numbered years which can be represented as
>     RRULE:FREQ=YEARLY;INTERVAL=2;BYDAY=TU;BYMONTHDAY=2,3,4,5,6,7,8
> but require some thinking to puzzle out; and some are quite difficult,
> e.g. Easter in some traditions is the first Sunday after the full
> moon.
> Like Easter, anything based on lunar calendars (most Arabic, Chinese,
> and Hebrew holidays) or Egyptian/Ethiopian/Coptic calendars just don't
> fit into the Gregorian calendar.
>
> cheers,
> mike
>
> 2010/4/28 Steve <steve_nor...@verizon.net>:
> >> For more options, visit this group athttp://groups.google.com/group/google-rfc-2445?hl=en.-Hide quoted text -

Mike Samuel

unread,
Apr 28, 2010, 5:18:12 PM4/28/10
to google-...@googlegroups.com
2010/4/28 Steve <steve_...@verizon.net>:
> Mike,
>
>  Thanks for the help on the holidays, I think I will manage that
> myself.  I did more testing on the weekday rule you gave me and it
> works great except when my date is on the 1st and 2nd of the month.
>
>  So if I would like to create a calendar entry for the 1st day of
> every month for 4 occurences but NOT on weekends I used, but the dates
> are not correct.
>
> RRULE:FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=30,31,1;BYDAY=MO,TU,WE,TH,FR;COUNT=4;BYSETPOS=-1
> mydate: 2010-04-01 Thu - Correct
> mydate: 2010-04-30 Fri - Correct
> mydate: 2010-05-31 Mon - Incorrect should be 2010-06-01 Tue
> mydate: 2010-06-30 Wed - Incorrect should be 2010-07-01 Thu

Depending on how you're using rrules, you can use more than one. E.g.
I believe if you're embedding them inside a vcalendar, then everywhere
one rrule can appear, you can have zero or more rrules and zero or one
exrule.

RRULE:FREQ=MONTHLY;BYMONTHDAY=-1,-2;BYDAY=TH,FR;BYSETPOS=-1
RRULE:FREQ=MONTHLY;BYMONTHDAY=1;BYDAY=MO,TU,WE,TH,FR

Unfortunately, you can't then apply a COUNT that affects both, so you
would have to apply UNTIL to both rules instead UNTIL is pure.

(BYMONTHDAY=-1,-2) matches the last two days of the month.

cheers,
mike
Reply all
Reply to author
Forward
0 new messages