1

I'm trying to add event in the calendar programatically. I want the event to repeat yearly, every first Monday in February for example. The rule I'm using is this:

FREQ=YEARLY;BYDAY=1MO;BYMONTH=2;INTERVAL=1;COUNT=11;

The problem is: if I create the event with starting date in January and set it to repeat every January, then it works fine. But, If i create the event with starting date in other month other than February, and set it to repeat by the same rule, the event won't repeat on Monday but on some other day. That day is different depending in which month is the starting day of the event. It seems like it counts number of day because on the leap year the day is changed by one.

UPDATE:

I noticed that if I create an event as mentioned above the following happens: If I create the event for example in February and set to be repeated in March, the rule gets the number of days in month from the moth where the DTSTART of the event is set (February). So, if I create an event in February and set it to be repeated the last day in March it will be repeated every 28th March or 29th on leap years (instead of 31st as expected).

Another example: I create event with DTSTART in January 2013 and set it to be repeated every first Monday in February. It creates the event on the date in February 2013 that corresponds to the first Monday in January 2013, in this case that is 7th February (because 7th January is first Monday in January 2013). Every next year the event will be repeated on the first Thursday of February.

nikmin
  • 1,803
  • 3
  • 28
  • 46
  • wait for 5 mins , i have implemented in past , checking the code. – Rahul Patil Feb 05 '13 at 09:35
  • @RahulPatil I'll wait, no problem :) – nikmin Feb 05 '13 at 10:05
  • @RahulPatil What happened, have you found it? – nikmin Feb 05 '13 at 11:17
  • sorry I dint get the code , i got this problem when working with Calendar application in GB , it has been long time . – Rahul Patil Feb 06 '13 at 05:43
  • 1
    given your update, you should be aware that the RFC5545 spec says that the DTSTART is the first occurence of your set. to avoid side effects you should set DTSTART to be the first occurence of your rule (or you should use a EXDATE, but support for EXDATE is even worse than proper RRULE computation). – Auberon Vacher Feb 06 '13 at 08:10
  • You should have written this as answer :) This is the solution to my problem :) THANKS – nikmin Feb 06 '13 at 08:12

2 Answers2

1

When adding the event DTSTART must be in the same month as the first occurrence of the event to avoid unwanted side effects

nikmin
  • 1,803
  • 3
  • 28
  • 46
0

can you give more details in terms of what you have and what you expect:

BEGIN:VCALENDAR
PRODID:byhand
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:20130205T090000Z
UID:SO_14702482_2b
SUMMARY:SO_14702482_2b
DTSTART:20130104T090000Z
RRULE:FREQ=YEARLY;BYDAY=1MO;BYMONTH=2;INTERVAL=1;COUNT=11;
END:VEVENT
END:VCALENDAR

will occur (tested on 2 different platforms) @09h00Z on: 20130104,20130204,20140203, 20150202,20160201, 20170206,...

while

BEGIN:VCALENDAR
PRODID:byhand
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:20130205T090000Z
UID:SO_14702482_1b
SUMMARY:SO_14702482_1b
DTSTART:20130204T090000Z
RRULE:FREQ=YEARLY;BYDAY=1MO;BYMONTH=2;INTERVAL=1;COUNT=11;
END:VEVENT
END:VCALENDAR

will occur (here also tested) @09h00Z on: 20130204, 20140203, 20150202,20160201, 20170206,...

the main difference being that as RFC5545 specified, DTSTART is part of the occurences.

Auberon Vacher
  • 4,655
  • 1
  • 24
  • 36
  • Example: The event `DTSTART` is `2013**01**05T090000Z`. The `RRULE` is `FREQ=YEARLY;BYDAY=1MO;**BYMONTH=2**;INTERVAL=1;COUNT=11;` What I expect is the event to be repeated every first Monday of February for the next 11 years (`20130204`, `20140203`, `20150202`, `20160201`, `20170206`...).What I get is the event in the android calendar is not repeated on Monday.It is repeated on Thursday:`20130207`, `20140206`, `20150205`...And I'm sure that in the rule it is set `BYDAY=1MO`,I checked it. But if I set `DTSTART` to be a date in February (same month as `BYMONTH`) it works fine. Strange, isn't it? – nikmin Feb 05 '13 at 10:18
  • I cannot test on Android but it definitively looks like the Android calendar you are using is not conforming to the standard ! – Auberon Vacher Feb 05 '13 at 10:46
  • I tried this on 2 devices running Android 4.1 and on one device running 4.0, it's the same. – nikmin Feb 05 '13 at 10:51
  • if you try it on Google calendar it will give the expected results, same with ical-mac.com (on top of what rfc5545 says) which leads me to the fact that it is the Android calendar which is not compliant. however it is not unsual : lack of compliance can be also seen with outlook.com. – Auberon Vacher Feb 05 '13 at 12:29