From beed6e0f0e198e74abfc3262db5b2b560ef76cbe Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 18 Jun 2012 14:47:58 +0200 Subject: [PATCH] Revert "Revert "create OC_Calendar_Object::generateStartEndDate function"" This reverts commit e3b58f6783aa173ceb9c26476ddf01dc570fc5e8. --- apps/calendar/lib/app.php | 30 ++---------------------------- apps/calendar/lib/object.php | 17 +++++++++++++++++ apps/calendar/lib/repeat.php | 19 +++---------------- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php index 17c23f4ea3..e3be8c8428 100644 --- a/apps/calendar/lib/app.php +++ b/apps/calendar/lib/app.php @@ -400,36 +400,10 @@ class OC_Calendar_App{ }else{ $object->expand($start, $end); foreach($object->getComponents() as $vevent){ - if(get_class($vevent) != 'Sabre_VObject_Component_VEvent'){ + if(!($vevent instanceof Sabre_VObject_Component_VEvent)){ continue; } - $dynamicoutput = array(); - $dtstart = $vevent->DTSTART; - $start_dt = $dtstart->getDateTime(); - $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); - $end_dt = $dtend->getDateTime(); - - if($allday){ - $dynamicoutput['start'] = $start_dt->format('Y-m-d'); - $end_dt->modify('-1 sec'); - $dynamicoutput['end'] = $end_dt->format('Y-m-d'); - }else{ - $start_dt->setTimezone(new DateTimeZone(self::$tz)); - $end_dt->setTimezone(new DateTimeZone(self::$tz)); - $dynamicoutput['start'] = $start_dt->format('Y-m-d H:i:s'); - $dynamicoutput['end'] = $end_dt->format('Y-m-d H:i:s'); - } - - // Handle exceptions to recurring events - /*$exceptionDateObjects = $vevent->select('EXDATE'); - $exceptionDateMap = Array(); - foreach ($exceptionDateObjects as $exceptionObject) { - foreach($exceptionObject->getDateTimes() as $datetime) { - $ts = $datetime->getTimestamp(); - $exceptionDateMap[idate('Y',$ts)][idate('m', $ts)][idate('d', $ts)] = true; - } - }*/ - + $dynamicoutput = OC_Calendar_Object::generateStartEndDate($vevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($vevent), self::$tz); $return[] = array_merge($staticoutput, $dynamicoutput); } } diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php index ba3fa814f3..07f2afb7b5 100644 --- a/apps/calendar/lib/object.php +++ b/apps/calendar/lib/object.php @@ -807,4 +807,21 @@ class OC_Calendar_Object{ $event = self::find($id); return ($event['repeating'] == 1)?true:false; } + + public static function generateStartEndDate($dtstart, $dtend, $tz){ + $start_dt = $dtstart->getDateTime(); + $end_dt = $dtend->getDateTime(); + $return = array(); + if($allday){ + $return['start'] = $start_dt->format('Y-m-d'); + $end_dt->modify('-1 hour'); + $return['end'] = $end_dt->format('Y-m-d'); + }else{ + $start_dt->setTimezone(new DateTimeZone($tz)); + $end_dt->setTimezone(new DateTimeZone($tz)); + $return['start'] = $start_dt->format('Y-m-d H:i:s'); + $return['end'] = $end_dt->format('Y-m-d H:i:s'); + } + return $return; + } } diff --git a/apps/calendar/lib/repeat.php b/apps/calendar/lib/repeat.php index 4b9cbdcd4b..6976378ebd 100644 --- a/apps/calendar/lib/repeat.php +++ b/apps/calendar/lib/repeat.php @@ -95,25 +95,12 @@ class OC_Calendar_Repeat{ $end->modify('+5 years'); $object->expand($start, $end); foreach($object->getComponents() as $vevent){ - if(get_class($vevent) != 'Sabre_VObject_Component_VEvent'){ + if(!($vevent instanceof Sabre_VObject_Component_VEvent)){ continue; } - $dtstart = $vevent->DTSTART; - $start_dt = $dtstart->getDateTime(); - $dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent); - $end_dt = $dtend->getDateTime(); - if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){ - $startdate = $start_dt->format('Y-m-d'); - $end_dt->modify('-1 sec'); - $enddate = $end_dt->format('Y-m-d'); - }else{ - $start_dt->setTimezone(new DateTimeZone('UTC')); - $end_dt->setTimezone(new DateTimeZone('UTC')); - $startdate = $start_dt->format('Y-m-d H:i:s'); - $enddate = $end_dt->format('Y-m-d H:i:s'); - } + $startenddate = OC_Calendar_Object::generateStartEndDate($vevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($vevent), 'UTC'); $stmt = OCP\DB::prepare('INSERT INTO *PREFIX*calendar_repeat (eventid,calid,startdate,enddate) VALUES(?,?,?,?)'); - $stmt->execute(array($id,OC_Calendar_Object::getCalendarid($id),$startdate,$enddate)); + $stmt->execute(array($id,OC_Calendar_Object::getCalendarid($id),$startenddate['start'],$startenddate['end'])); } return true; }