mangstadt / biweekly

biweekly is an iCalendar library written in Java.
BSD 2-Clause "Simplified" License
323 stars 44 forks source link

Order of RRULE components produces different results #117

Closed tjmorgan0 closed 2 years ago

tjmorgan0 commented 2 years ago

"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;
                }
            }
        }
    }
mangstadt commented 2 years ago

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

tjmorgan0 commented 2 years ago

Interesting....

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

tjmorgan0 commented 2 years ago

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'

mangstadt commented 2 years ago

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.