--- date_api_ical.inc 2009-05-10 21:44:14.000000000 +0900 +++ date_api_ical-new.inc 2009-11-11 10:32:10.000000000 +0900 @@ -195,19 +195,30 @@ function date_ical_parse($icaldatafolded if (isset($subgroup['DURATION'])) { date_ical_parse_duration($subgroup, 'DURATION'); } + // iCal spec states 'The "DTEND" property for a "VEVENT" calendar component specifies the + // non-inclusive end of the event' + // This is fine for hours such as 11:00~12:00 means one hour, not two but + // for whole days the current calendar code assumes the end date is inclusive so Oct 30 ~ Oct 31 is + // interpreted as two days, not one. So make an adjustment to account for this difference in logic + if (!empty($subgroup['DTEND']) && (!empty($subgroup['DTEND']['all_day']))) { + // make the end date one day earlier + $subgroup['DTEND']['datetime'] = date( 'Y-m-d', date_convert($subgroup['DTEND']['datetime'], DATE_DATETIME, DATE_UNIX) - 86400); + } // Add a top-level indication for the 'All day' condition. // Leave it in the individual date components, too, so it // is always available even when you are working with only // a portion of the VEVENT array, like in Feed API parsers. $subgroup['all_day'] = FALSE; - if (!empty($subgroup['DTSTART']) && (!empty($subgroup['DTSTART']['all_day']) || - (empty($subgroup['DTEND']) && empty($subgroup['RRULE']) && empty($subgroup['RRULE']['COUNT'])))) { - // Many programs output DTEND for an all day event as the - // following day, reset this to the same day for internal use. - $subgroup['all_day'] = TRUE; + // if a start datetime is defined AND there is no definition for the end datetime + // THEN make the end datetime equal the start datetime + // and if it is an all day event define the entire event as a single all day event + if (!empty($subgroup['DTSTART']) && + (empty($subgroup['DTEND']) && empty($subgroup['RRULE']) && empty($subgroup['RRULE']['COUNT']))) { $subgroup['DTEND'] = $subgroup['DTSTART']; - } - // Add this element to the parent as an array under the + if (!empty($subgroup['DTSTART']['all_day'])) { + $subgroup['all_day'] = TRUE; + } + } // Add this element to the parent as an array under the // component name default: prev($subgroups);