我的军刀中有一个iCalendar事件:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//CalDAV Client//EN
BEGIN:VEVENT
UID:5e44cec8-33ed-4f24-82c7-f33483afa50d
DTSTART:20200805T080000Z
SUMMARY:summary
STATUS:CONFIRMED
TRANSP:OPAQUE
DURATION:PT30M
CATEGORIES:RESERVATION
DTSTAMP:20200716T211928Z
END:VEVENT
END:VCALENDAR
它从'2020-08-05T08:00:00.000Z'
开始,持续时间为30分钟,在'2020-08-05T08:30:00.000Z'
结束。
如果我提交以下查询:
<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav"
xmlns:cs="http://calendarserver.org/ns/"
xmlns:ca="http://apple.com/ns/ical/"
xmlns:d="DAV:">
<d:prop>
<c:calendar-data />
</d:prop>
<c:filter>
<c:comp-filter name="VCALENDAR">
<c:comp-filter name="VEVENT">
<c:time-range start="20200805T080000Z" end="20200805T180000Z"/>
</c:comp-filter>
</c:comp-filter>
</c:filter>
<c:timezone>GMT</c:timezone>
</c:calendar-query>
返回上述事件。然而,如果我将start=...
移动一秒钟,就像start="20200805T080001Z"
一样,它不会返回。
根据第9.9节或Caldav RFC 4791,它应该被返回。上述章节中的条件:
(start < DTSTART+DURATION AND end > DTSTART)
我发现,我使用的是Mongo后端,而不是Sabre的PDO后端,并且提到的Mongo后端有一个PDO没有的错误。
导致错误的代码:
$endDate = clone $component->DTSTART->getDateTime();
$endDate->add(VObjectDateTimeParser::parse($component->DURATION->getValue()));
$lastOccurence = $endDate->getTimeStamp();
endDate
是不可变日期,因此需要重新分配endDate
以使add
函数生效。
固定代码:
$endDate = clone $component->DTSTART->getDateTime();
$endDate = $endDate->add(VObjectDateTimeParser::parse($component->DURATION->getValue()));
$lastOccurence = $endDate->getTimeStamp();
您也可以在PDO后端的github页面上看到这一点的正确实现。