I am using google-rfc2445 library (com.google.ical) to parse RRULE.
In the test below the rrule UNTIL is set in the past (year 1999) and the dtStart is set as now. I am expecting 0 result but somehow getting 1 result which seems like the dtStart. I am dumbfounded why it is including an item out of the UNTIL bound. Is that the expected behavior?
@Test
public void testRruleExpiryInPast1() {
String rruleString = "RRULE:FREQ=DAILY;INTERVAL=1;UNTIL=19990103T000000Z";
DateTime startDate = DateTime.now(DateTimeZone.UTC);
System.out.println("startDate timeZone =" + startDate.getZone());
try {
DateTimeIterable localDateIterable = DateTimeIteratorFactory.createDateTimeIterable(rruleString, startDate, startDate.getZone(), false);
DateTimeIterator iterator = localDateIterable.iterator();
while (iterator.hasNext()) {
DateTime next = iterator.next();
System.out.println(next);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
The above test Outputs
startDate timeZone =UTC
2022-02-06T18:52:31.000Z
Update1: according to this answer, ICAL in google calendar has extra event , it seem like the DTSTART will always be the first occurrence regardless of UNTIL being in the past or not. I find this strange. Now I have resorted to regex parsing the rrule string to determine whether there is UNTIL or not and if there is whether it is in the past. :(
Your use case is a little bit of a logical corner case.
Technically the RFC2245 in the section section-4.3.10 says:
The underlying logic being that the first instance is specified by
DTSTARTand that subsequent instances should be derived from theRRULE.In your case since you are specifying
UNTILbeforeDTSTARTwe are to the best of my knowledge in a grey area where the RFC does not specify how the RRULE instances should be generated.I suspect that the Google library is sticking to the letter of the RFC and pre-pending
DTSARTto the list of instances without checking if it before the date specified byUNTILsince RFC does not mention this.