From d875429fcb5117ad55e7cf7cf7838536deb5be23 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 27 Sep 2009 08:23:01 +0000 Subject: [PATCH] "patch #2270: export start- and enddate as date, if user set no time (rest of patch not necessary for trunk)" --- infolog/inc/class.infolog_ical.inc.php | 34 ++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/infolog/inc/class.infolog_ical.inc.php b/infolog/inc/class.infolog_ical.inc.php index a33e63a7d3..08ebf67f74 100644 --- a/infolog/inc/class.infolog_ical.inc.php +++ b/infolog/inc/class.infolog_ical.inc.php @@ -189,19 +189,15 @@ class infolog_ical extends infolog_bo if ($taskData['info_startdate']) { - $vevent->setAttribute('DTSTART',$taskData['info_startdate']); + self::setDateOrTime($vevent,'DTSTART',$taskData['info_startdate']); } - if ($taskData['info_enddate']) { - $parts = @getdate($taskData['info_enddate']); - $value = @mktime(12, 0, 0, $parts['mon'], $parts['mday'], $parts['year']); - $vevent->setAttribute('DUE', $value); + self::setDateOrTime($vevent,'DUE',$taskData['info_enddate']); } - if ($taskData['info_datecompleted']) { - $vevent->setAttribute('COMPLETED',$taskData['info_datecompleted']); + self::setDateOrTime($vevent,'COMPLETED',$taskData['info_datecompleted']); } $vevent->setAttribute('DTSTAMP',time()); @@ -222,6 +218,30 @@ class infolog_ical extends infolog_bo return $retval; } + /** + * Check if use set a date or date+time and export it as such + * + * @param Horde_iCalendar_* $vevent + * @param string $attr attribute name + * @param int $value timestamp + */ + static function setDateOrTime($vevent,$attr,$value) + { + // check if use set only a date --> export it as such + if (date('H:i',$value) == '00:00') + { + $vevent->setAttribute($attr,array( + 'year' => date('Y',$value), + 'month' => date('m',$value), + 'mday' => date('d',$value), + ),array('VALUE' => 'DATE')); + } + else + { + $vevent->setAttribute($attr,$value); + } + } + /** * Import a VTODO component of an iCal *