/** * @expectedException InvalidArgumentException */ function testGetDateTimeDateInvalid() { $elem = new Sabre_VObject_Element_DateTime('DTSTART', 'bla'); $dt = $elem->getDateTime(); }
public static function updateVCalendarFromRequest($request, $vcalendar) { $title = $request["title"]; $location = $request["location"]; $categories = isset($request["categories"]) ? $request["categories"] : null; $allday = isset($request["allday"]); $from = $request["from"]; $fromtime = $request["fromtime"]; $to = $request["to"]; $totime = $request["totime"]; $description = $request["description"]; //$repeat = $request["repeat"]; /*switch($request["repeatfreq"]){ case "DAILY": $repeatfreq = "DAILY"; case "WEEKLY": $repeatfreq = "WEEKLY"; case "WEEKDAY": $repeatfreq = "DAILY;BYDAY=MO,TU,WE,TH,FR"; //load weeksdayss from userconfig when weekdays are choosable case "": $repeatfreq = ""; case "": $repeatfreq = ""; case "": $repeatfreq = ""; default: $repeat = "false"; }*/ $repeat = "false"; $now = new DateTime(); $vevent = $vcalendar->VEVENT[0]; $last_modified = new Sabre_VObject_Element_DateTime('LAST-MODIFIED'); $last_modified->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); $vevent->__set('LAST-MODIFIED', $last_modified); $dtstamp = new Sabre_VObject_Element_DateTime('DTSTAMP'); $dtstamp->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); $vevent->DTSTAMP = $dtstamp; $vevent->SUMMARY = $title; $dtstart = new Sabre_VObject_Element_DateTime('DTSTART'); $dtend = new Sabre_VObject_Element_DateTime('DTEND'); if ($allday) { $start = new DateTime($from); $end = new DateTime($to . ' +1 day'); $dtstart->setDateTime($start, Sabre_VObject_Element_DateTime::DATE); $dtend->setDateTime($end, Sabre_VObject_Element_DateTime::DATE); } else { $timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone", "Europe/London"); $timezone = new DateTimeZone($timezone); $start = new DateTime($from . ' ' . $fromtime, $timezone); $end = new DateTime($to . ' ' . $totime, $timezone); $dtstart->setDateTime($start, Sabre_VObject_Element_DateTime::LOCALTZ); $dtend->setDateTime($end, Sabre_VObject_Element_DateTime::LOCALTZ); } $vevent->DTSTART = $dtstart; $vevent->DTEND = $dtend; unset($vevent->DURATION); if ($location != "") { $vevent->LOCATION = $location; } else { unset($vevent->LOCATION); } if ($description != "") { $vevent->DESCRIPTION = $description; } else { unset($vevent->DESCRIPTION); } if (!empty($categories)) { $vevent->CATEGORIES = join(',', $categories); } else { unset($vevent->CATEGORIES); } /*if($repeat == "true"){ $vevent->RRULE = $repeat; }*/ return $vcalendar; }
/** * get datetime from sabredav datetime property (user TZ is fallback) * * @param Sabre_VObject_Element_DateTime $dateTime * @param boolean $_useUserTZ * @return Tinebase_DateTime * * @todo try to guess some common timezones */ protected function _convertToTinebaseDateTime(Sabre_VObject_Element_DateTime $dateTimeProperty, $_useUserTZ = FALSE) { try { $dateTime = $dateTimeProperty->getDateTime(); } catch (Exception $e) { if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) { Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Error: ' . $e->getMessage()); } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString()); } $dateTimeProperty['TZID'] = (string) Tinebase_Core::get(Tinebase_Core::USERTIMEZONE); $dateTime = $dateTimeProperty->getDateTime(); } $tz = $_useUserTZ ? (string) Tinebase_Core::get(Tinebase_Core::USERTIMEZONE) : $dateTime->getTimezone(); $result = new Tinebase_DateTime($dateTime->format(Tinebase_Record_Abstract::ISO8601LONG), $tz); return $result; }
/** * Returns the type of Date format. * * This method returns one of the format constants. If no date was set, * this method will return null. * * @return int|null */ public function getDateType() { if ($this->dateType) { return $this->dateType; } if (!$this->value) { $this->dateTimes = null; $this->dateType = null; return null; } $dts = array(); foreach (explode(',', $this->value) as $val) { list($type, $dt) = Sabre_VObject_Element_DateTime::parseData($val, $this); $dts[] = $dt; $this->dateType = $type; } $this->dateTimes = $dts; return $this->dateType; }
/** * @depends testValues */ function testComplexExclusions() { $ev = new Sabre_VObject_Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=10'; $dtStart = new Sabre_VObject_Element_DateTime('DTSTART'); $tz = new DateTimeZone('Canada/Eastern'); $dtStart->setDateTime(new DateTime('2011-01-01 13:50:20', $tz), Sabre_VObject_Element_DateTime::LOCALTZ); $exDate1 = new Sabre_VObject_Element_MultiDateTime('EXDATE'); $exDate1->setDateTimes(array(new DateTime('2012-01-01 13:50:20', $tz), new DateTime('2014-01-01 13:50:20', $tz)), Sabre_VObject_Element_DateTime::LOCALTZ); $exDate2 = new Sabre_VObject_Element_MultiDateTime('EXDATE'); $exDate2->setDateTimes(array(new DateTime('2016-01-01 13:50:20', $tz)), Sabre_VObject_Element_DateTime::LOCALTZ); $ev->add($dtStart); $ev->add($exDate1); $ev->add($exDate2); $vcal = Sabre_VObject_Component::create('VCALENDAR'); $vcal->add($ev); $it = new Sabre_VObject_RecurrenceIterator($vcal, (string) $ev->uid); $this->assertEquals('yearly', $it->frequency); $this->assertEquals(1, $it->interval); $this->assertEquals(10, $it->count); $max = 20; $result = array(); foreach ($it as $k => $item) { $result[] = $item; $max--; if (!$max) { break; } } $this->assertEquals(array(new DateTime('2011-01-01 13:50:20', $tz), new DateTime('2013-01-01 13:50:20', $tz), new DateTime('2015-01-01 13:50:20', $tz), new DateTime('2017-01-01 13:50:20', $tz), new DateTime('2018-01-01 13:50:20', $tz), new DateTime('2019-01-01 13:50:20', $tz), new DateTime('2020-01-01 13:50:20', $tz)), $result); }