biweekly icon indicating copy to clipboard operation
biweekly copied to clipboard

Order of RRULE components produces different results

Open tjmorgan0 opened this issue 2 years ago • 4 comments

"DTSTART:20220606T110000Z\nRRULE:FREQ=WEEKLY;INTERVAL=1;WKST=SU;BYDAY=TH,FR" only provides the Thursdays as occurrences. When the specification is modified to

"DTSTART:20220606T110000Z\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=TH,FR;WKST=SU" it works as expected.

Here's the Java code snippet that generates the different results depending on the rruleString.

if (rruleString.length() != 0) { String str = "BEGIN:VCALENDAR\r\n" + "VERSION:2.0\r\n" + "PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN\r\n" + "BEGIN:VEVENT\r\n" + rruleString + "END:VEVENT\r\n" + "END:VCALENDAR\r\n";

        ICalendar ical = Biweekly.parse(str).first();

        VEvent vEvent = ical.getEvents().get(0);
        DateStart dateStart = vEvent.getDateStart();
        OffsetDateTime startDateTime = getOffsetDateTime(dateStart.getValue());

        // Are we before the startDateTime?
        if (startDateTime.isAfter(adjustDateTimeRef)) {
            rtnVal = startDateTime;
        } else {
            Log.d("DateStart = ", dateStart.toString());
            TimeZone timeZone =  TimeZone.getDefault();
            DateIterator it = vEvent.getDateIterator(timeZone);

            // Look for next
            while (it.hasNext()) {
                OffsetDateTime nextDate = getOffsetDateTime(it.next());
                Log.d(TAG, "nextDateTime = " + nextDate);
                if (nextDate.isAfter(adjustDateTimeRef)) {
                    rtnVal = nextDate;
                    break;
                }
            }
        }
    }

tjmorgan0 avatar Jun 21 '22 18:06 tjmorgan0

Unable to reproduce. Both RRULE strings produce the same dates for me.

https://github.com/mangstadt/biweekly/blob/master/src/test/java/biweekly/issues/Issue117.java

mangstadt avatar Jun 25 '22 14:06 mangstadt

Interesting....

I'll see If I can still create the issue and get back to you.

tjmorgan0 avatar Jun 28 '22 17:06 tjmorgan0

I was able to recreate the problem. The key is not including the '\n' between the end of the RRULE and the "END/VEVENT.....

My code has the following::

... "BEGIN:VEVENT\r\n" + rruleString + "END:VEVENT\r\n" + ...

Your test code has this:

... "BEGIN:VEVENT\r\n" + "DTSTART:20220606T110000Z\n" + rruleString + "\r\n" + "END:VEVENT\r\n" + ...

The '\r' appears to be irrelevant. I assuming your using the '\n' as an important part of the parsing algorithm.

I can fix my code. by adding the '\n'

tjmorgan0 avatar Jun 28 '22 19:06 tjmorgan0

The iCalendar specifications require the use of the \r\n newline sequence. However, biweekly will accept \r or \n as well.

Each property must end in \r\n, \r or \n in order for biweekly to parse it.

mangstadt avatar Jun 30 '22 00:06 mangstadt