Biweekly/google-rfc-2445 RRule different behaviour based on start date

85 Views Asked by At

Different behaviour of RRULE based on start time :

Hi, I am currently trying to write a cron to rrule convertor and encountered some issues with some particular rules. For the following rule : "FREQ=YEARLY;BYMONTH=1,2,3,4,5,6,7,8,9,10,11,12;BYMONTHDAY=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYHOUR=0,10,20;BYMINUTE=0"

The behaviour of the dates iterator iss different depending on what the start time specified is :

        final String rule2 = "FREQ=YEARLY;BYMONTH=1,2,3,4,5,6,7,8,9,10,11,12;BYMONTHDAY=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYHOUR=0,10,20;BYMINUTE=0";
        final Date startDate = new SimpleDateFormat("yyyy-MM-dd").parse("2019-10-01");
        final Date startDate2 = new SimpleDateFormat("yyyy-MM-dd").parse("2019-12-01");

        System.out.println("Biweekly Rule Date 1");
        final List<Date> biweeklyStartDate1 = biweeklyDates(rule2, startDate, 100);
        System.out.println("Biweekly Rule Date 1 Result Count " + biweeklyStartDate1.size());

        System.out.println("Biweekly Rule Date 2");
        final List<Date> biweeklyStartDate2 = biweeklyDates(rule2, startDate2, 100);
        System.out.println("Biweekly Rule Date 2 Result Count " + biweeklyStartDate2.size());

   private static List<Date> biweeklyDates(final String rule, final Date date, final int limit) {
        final RecurrenceRuleScribe scribe = new RecurrenceRuleScribe();
        final ParseContext context = new ParseContext();
        context.setVersion(ICalVersion.V2_0);
        final RecurrenceRule recurrenceRule = scribe.parseText("RRULE:" + rule,null, new ICalParameters(), context);
        final DateIterator iterator = recurrenceRule.getDateIterator(date, TimeZone.getTimeZone("GMT"));

        final List<Date> values  = new ArrayList<>();
        while (iterator.hasNext()) {
            final Date next = iterator.next();
            values.add(next);
            System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(next));
            if (values.size() >= limit) {
                break;
            }
        }
        return values;
    }

In this example I try to retrieve a 100 occurences using the same rule. The occurences returned differ based on start time specified. The first date would return the expected 100 results, the second one would return a single invalid occurence, which seem to be the start date. It seems to be caused by last month of the year, whn specifying another date with December, the same return seems to be returned. Google-rfc-2445 has the same behaviour but ical4j and some other rrule evaluators from other languages were able to produce the expected results.

0

There are 0 best solutions below