有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在某些情况下,使用googlerfc2445(iCalendar)时会返回java开始日期

为了测试google-rfc-2445(一个IETFRFC 2445iCalendar的Java实现)的性能,我运行了很多RRULEs

我看到,在某些情况下,我从该方法返回的列表中返回了开始日期

测试非常简单:

private static void runGoogleTests() throws ParseException
{
    DateTimeZone dtz = DateTimeZone.UTC;
    DateTime dtStart = new DateTime("2014-11-22T00:00:00Z", dtz);//SATURDAY
    DateTimeIterable dti = DateTimeIteratorFactory.createDateTimeIterable("RRULE:FREQ=WEEKLY;COUNT=10;BYDAY=MO", dtStart, dtz, true);

    System.out.println("Size of iterable = " + Iterators.size(dti.iterator()));
    for(DateTime dateTime : dti)
    {
        System.out.println(dateTime);
    }
}

工厂返回的列表返回此列表

第一个日期是开始日期,星期六不应该在那里。RRULE还包含一个COUNT=10,那么为什么返回11呢

Size of iterable = 11
2014-11-22T00:00:00.000Z
2014-11-24T00:00:00.000Z
2014-12-01T00:00:00.000Z
2014-12-08T00:00:00.000Z
2014-12-15T00:00:00.000Z
2014-12-22T00:00:00.000Z
2014-12-29T00:00:00.000Z
2015-01-05T00:00:00.000Z
2015-01-12T00:00:00.000Z
2015-01-19T00:00:00.000Z
2015-01-26T00:00:00.000Z

使用Google-rfc-2445的人以前一定遇到过这个问题

我在项目页面上发布了这个问题,但是那里非常安静。 Link to the issue on google-rfc-2445 page


共 (2) 个答案

  1. # 1 楼答案

    试着这样做:

    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();
    
    }
    

    其思想是提前一天开始序列,并使用EXDATE规则排除第一个日期

  2. # 2 楼答案

    RFC2445 section 4.3.10 Recurrence Rule指定

    [...] 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. [...]

    因此,虽然返回列表中存在DTSTART是正常的,但不太期望的是返回列表的大小

    考虑到RFC2445规范,将DTSTART作为循环的第一个实例更有意义,以确保其他日历正确理解ical文件

    还需要注意的是RFC2445RFC5545淘汰,它还指定DTSTART作为RRULE的第一个实例(甚至强调它,注意:添加的单词总是(empahsis由我添加)

    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.