Displaying Google Calendars in PHP iCal

PHP iCalendar solves a couple problems I’m working on, but I needed a solution to fix the duration display for Gcal-managed ICS calendars.

As it turns out, a fix can be found in the forums, and the trick is to insert the following code in functions/ical_parser.php.


case 'DURATION':
	if (($first_duration == TRUE) && (!stristr($field, '=DURATION'))) {
		ereg ('^P([0-9]{1,2}[W])?([0-9]{1,2}[D])?([T]{0,1})?([0-9]{1,2}[H])?([0-9]{1,2}[M])?([0-9]{1,}[S])?', $data, $duration); 
	
		$weeks = str_replace('W', '', $duration[1]);
		$days = str_replace('D', '', $duration[2]);
		$hours = str_replace('H', '', $duration[4]);
		$minutes = str_replace('M', '', $duration[5]);
		$seconds = str_replace('S', '', $duration[6]);
		
		// Convert seconds to hours, minutes, and seconds
		if ($seconds > 60) {
			$rem_seconds = $seconds % 60;
			$minutes = $minutes + (($seconds - $rem_seconds) / 60);
			$seconds = $rem_seconds;
		}
		if ($minutes > 60) {
			$rem_minutes = $minutes % 60;
			$hours = $hours + (($minutes - $rem_minutes) / 60);
			$minutes = $rem_minutes;
		}
		
		$the_duration = ($weeks * 60 * 60 * 24 * 7) + ($days * 60 * 60 * 24) + ($hours * 60 * 60) + ($minutes * 60) + ($seconds);
		$first_duration = FALSE;
	}
	break;

Hopefully this gets worked into the baseline with the next release.

bug, duration, fix, gcal, google calendars, ical, ics, php icalendar