iCalendar排除日期范围

时间:2016-01-07 23:17:48

标签: php calendar export google-calendar-api icalendar

我正在研究学校时间表系统,目前正在开发一个允许以iCalendar(.ics)格式导出数据的PHP脚本。导出数据的目标用例是将其导入Google日历。

由于我们学校的学期之间有假期(由开始和结束日期指定),从iCalendar重复规则(RRULE)中排除假期的最佳方式是什么?。请记住,一次导出可能有许多不同的计划。

我确实尝试在所有假期使用EXDATE;VALUE=DATE:YYYYMMDD,YYYYMMDD,YYYYMMDD...,但Google日历并没有排除日期,可能是因为时间表也附加时间,因此它们不匹配。

我还会以iCalendar格式提供其中一个事件的数据,假日天数逐个排除(没有工作的那个)

BEGIN:VCALENDAR
PRODID:-//Gregor Eesmaa/NONSGML Poska timetables//ET
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
UID:schedule-1442@jpg.tartu.ee
SUMMARY:French
DESCRIPTION:
LOCATION:Room 210
DTSTART:20151215T123000Z
DTEND:20151215T134500Z
RRULE:FREQ=WEEKLY;UNTIL=20160211;INTERVAL=1;BYDAY=TU
EXDATE;VALUE=DATE:20151223,20151224,20151225,20151226,20151227,20151228,20151229,20151230,20151231,20160101,20160102,20160103,20160104,20160105,20160106,20160107,20160108,20160109,20160110,20160319,20160320,20160321,20160322,20160323,20160324,20160325,20160326,20160327,20160415,20160416,20160417,20160418,20160607,20160608,20160609,20160610,20160611,20160612,20160613,20160614,20160615,20160616,20160617,20160618,20160619,20160620,20160621,20160622,20160623,20160624,20160625,20160626,20160627,20160628,20160629,20160630,20160701,20160702,20160703,20160704,20160705,20160706,20160707,20160708,20160709,20160710,20160711,20160712,20160713,20160714,20160715,20160716,20160717,20160718,20160719,20160720,20160721,20160722,20160723,20160724,20160725,20160726,20160727,20160728,20160729,20160730,20160731,20160801,20160802,20160803,20160804,20160805,20160806,20160807,20160808,20160809,20160810,20160811,20160812,20160813,20160814,20160815,20160816,20160817,20160818,20160819,20160820,20160821,20160822,20160823,20160824,20160825,20160826,20160827,20160828,20160829,20160830,20160831
LAST-MODIFIED:20160102T123758Z
DTSTAMP:20160107T232137Z
END:VEVENT
END:VCALENDAR

3 个答案:

答案 0 :(得分:1)

如果DTSTART是日期时间值,那么EXDATEs也必须是日期时间。我建议你将T123000Z附加到每个EXDATE,以使它们实际指向有效的实例启动。然后他们将被正确排除。

答案 1 :(得分:0)

根据其他SO issue,您似乎没有在EXDATE中设置任何排除日期。根据{{​​3}}规范,EXDATE可以设置为DATE

根据对其他问题的回答,您的EXDATE应该是

EXDATE:20151223,20151224,20151225,20151226,20151227,20151228,20151229,20151230,20151231,20160101,20160102,20160103,20160104,20160105,20160106,20160107,20160108,20160109,20160110,20160319,20160320,20160321,20160322,20160323,20160324,20160325,20160326,20160327,20160415,20160416,20160417,20160418,20160607,20160608,20160609,20160610,20160611,20160612,20160613,20160614,20160615,20160616,20160617,20160618,20160619,20160620,20160621,20160622,20160623,20160624,20160625,20160626,20160627,20160628,20160629,20160630,20160701,20160702,20160703,20160704,20160705,20160706,20160707,20160708,20160709,20160710,20160711,20160712,20160713,20160714,20160715,20160716,20160717,20160718,20160719,20160720,20160721,20160722,20160723,20160724,20160725,20160726,20160727,20160728,20160729,20160730,20160731,20160801,20160802,20160803,20160804,20160805,20160806,20160807,20160808,20160809,20160810,20160811,20160812,20160813,20160814,20160815,20160816,20160817,20160818,20160819,20160820,20160821,20160822,20160823,20160824,20160825,20160826,20160827,20160828,20160829,20160830,20160831

希望这有帮助!

答案 2 :(得分:0)

我发布了这个问题,寻找一个排除整个范围的解决方案。在仔细考虑之后,我决定通过仅排除实际发生事件的日期时间来正确地做到这一点。这减少了出口的文件大小三倍。

我还添加了使用RRULE建议的时区信息。现在,法语课程事件将如下所示:

BEGIN:VEVENT
UID:schedule-1442@jpg.tartu.ee
SUMMARY:French
DESCRIPTION:
LOCATION:Room 210
DTSTART;TZID=Europe/Tallinn:20151215T143000
DTEND;TZID=Europe/Tallinn:20151215T154500
RRULE:FREQ=WEEKLY;UNTIL=20160211;INTERVAL=1;BYDAY=TU
EXDATE;TZID=Europe/Tallinn:20151229T143000,20160105T143000
CREATED:20160102T123758Z
LAST-MODIFIED:20160102T123758Z
DTSTAMP:20160108T115122Z
END:VEVENT