Search code examples
javaicalendarrfc2445

end date(UNTIL) is excluded when using google-rfc-2445 createDateTimeIterator to generate date range


I need to know how do i avoid UNTIL or end date getting excluded in the date range being created in this - https://stackoverflow.com/a/27628608/5311573

Please help.

I'm trying to get the date range using the answer given in above link but it excludes the end date every time.

StartDate = 2020-04-21T00:00:00.000+05:30;
RRULE:FREQ=DAILY;INTERVAL=1;UNTIL=20200428

it will return me below result:

2020-04-20T18:30:00.000Z
2020-04-21T18:30:00.000Z
2020-04-22T18:30:00.000Z
2020-04-23T18:30:00.000Z
2020-04-24T18:30:00.000Z
2020-04-25T18:30:00.000Z
2020-04-26T18:30:00.000Z
2020-04-27T18:30:00.000Z

Solution

  • Your start date and time appears to be 2020-04-20T18:30:00.000Z despite your pseudo code above. Because that is what you have listed as your results: recurrences at 18.30.

    With a daily recurrence at those times, 2020-04-28T18:30:00.000Z would be AFTER 2020-04-20T00:00:000Z.

    So make the start date or datetime and end date or datetime consistent. From https://icalendar.org/iCalendar-RFC-5545/3-3-10-recurrence-rule.html, it says:

    The UNTIL rule part defines a DATE or DATE-TIME value that bounds the recurrence rule in an inclusive manner. If the value specified by UNTIL is synchronized with the specified recurrence, this DATE or DATE-TIME becomes the last instance of the recurrence. The value of the UNTIL rule part MUST have the same value type as the "DTSTART" property. Furthermore, if the "DTSTART" property is specified as a date with local time, then the UNTIL rule part MUST also be specified as a date with local time. If the "DTSTART" property is specified as a date with UTC time or a date with local time and time zone reference, then the UNTIL rule part MUST be specified as a date with UTC time.

    change UNTIL to 2020-04-28T18:30:00.000Z if UTC time intended or 2020-04-28T18:30:00.000 if floating time intended.
    Basically DTSTART And UNTIL must match.