function testGetDateTimeCached() { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); $elem = new DateTime('DTSTART'); $elem->setDateTime($dt); $this->assertEquals($elem->getDateTime(), $dt); }
/** * Create a Sabre\VObject\Property instance from a PHP DateTime object * * @param string Property name * @param object DateTime */ public function datetime_prop($name, $dt, $utc = false, $dateonly = null) { $is_utc = $utc || ($tz = $dt->getTimezone()) && in_array($tz->getName(), array('UTC', 'GMT', 'Z')); $is_dateonly = $dateonly === null ? (bool) $dt->_dateonly : (bool) $dateonly; $vdt = new VObject\Property\DateTime($name); $vdt->setDateTime($dt, $is_dateonly ? VObject\Property\DateTime::DATE : ($is_utc ? VObject\Property\DateTime::UTC : VObject\Property\DateTime::LOCALTZ)); // register timezone for VTIMEZONE block if (!$is_utc && !$dateonly && $tz && ($tzname = $tz->getName())) { $ts = $dt->format('U'); if (is_array($this->vtimezones[$tzname])) { $this->vtimezones[$tzname][0] = min($this->vtimezones[$tzname][0], $ts); $this->vtimezones[$tzname][1] = max($this->vtimezones[$tzname][1], $ts); } else { $this->vtimezones[$tzname] = array($ts, $ts); } } return $vdt; }
/** * @depends testValues */ function testComplexExclusions() { $ev = new Component('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=10'; $dtStart = new Property\DateTime('DTSTART'); $tz = new DateTimeZone('Canada/Eastern'); $dtStart->setDateTime(new DateTime('2011-01-01 13:50:20', $tz), Property\DateTime::LOCALTZ); $exDate1 = new Property\MultiDateTime('EXDATE'); $exDate1->setDateTimes(array(new DateTime('2012-01-01 13:50:20', $tz), new DateTime('2014-01-01 13:50:20', $tz)), Property\DateTime::LOCALTZ); $exDate2 = new Property\MultiDateTime('EXDATE'); $exDate2->setDateTimes(array(new DateTime('2016-01-01 13:50:20', $tz)), Property\DateTime::LOCALTZ); $ev->add($dtStart); $ev->add($exDate1); $ev->add($exDate2); $vcal = Component::create('VCALENDAR'); $vcal->add($ev); $it = new 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); }
/** * Create a Sabre\VObject\Property instance from a PHP DateTime object * * @param string Property name * @param object DateTime */ public static function datetime_prop($name, $dt, $utc = false, $dateonly = null) { $is_utc = $utc || ($tz = $dt->getTimezone()) && in_array($tz->getName(), array('UTC', 'GMT', 'Z')); $is_dateonly = $dateonly === null ? (bool) $dt->_dateonly : (bool) $dateonly; $vdt = new VObject\Property\DateTime($name); $vdt->setDateTime($dt, $is_dateonly ? VObject\Property\DateTime::DATE : ($is_utc ? VObject\Property\DateTime::UTC : VObject\Property\DateTime::LOCALTZ)); return $vdt; }