Start date returns in some cases when using google-rfc-2445 (iCalendar)

☆樱花仙子☆ 提交于 2019-12-03 12:47:07

RFC2445 section 4.3.10 Recurrence Rule specifies that

[...] The COUNT rule part defines the number of occurrences at which to range-bound the recurrence. The "DTSTART" property value, if specified, counts as the first occurrence. [...]

so while the presence of the DTSTART in the returned list is normal, what is less expected is the size of the returned list.

Given the RFC2445 specification, it makes more sense to have the DTSTART being the first instance of the recurrence to also insure that other calendars understand the ical file properly.

Also to be noted RFC2445 is obsoleted by RFC5545 which also specifies the DTSTART as the first instance of the RRULE (and even emphasizes it, note: the added word always (empahsis added by me)

RFC5545 RRULE section: The COUNT rule part defines the number of occurrences at which to range-bound the recurrence. The "DTSTART" property value always counts as the first occurrence.

Try something like this:

public static DateTimeIterator createDateTimeIterator(
        final String repeatRules,
        final DateTime scheduleStart,
        final DateTimeZone timeZone) throws ParseException {

    DateTime start = scheduleStart;
    String exdate = "";
    final RRule rrule = new RRule(repeatRules);
    if (rrule.getFreq().ordinal() > Frequency.DAILY.ordinal()) {
        start = start.minusDays(1);
        exdate = "\nEXDATE:"
                + ISODateTimeFormat.basicDateTimeNoMillis().print(start.withZone(timeZone).toLocalDateTime());
    }

    final DateTimeIterable dateIterable = DateTimeIteratorFactory.createDateTimeIterable(
            repeatRules + exdate,
            start,
            timeZone,
            true);

    return dateIterable.iterator();

}

The idea is to start the sequence one day earlier and to exclude the first date by using EXDATE rule.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!