function timeRangeTestData() { $tests = []; $calendar = new VCalendar(); $vevent = $calendar->createComponent('VEVENT'); $vevent->DTSTART = '20111223T120000Z'; $tests[] = [$vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $vevent2 = clone $vevent; $vevent2->DTEND = '20111225T120000Z'; $tests[] = [$vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $vevent3 = clone $vevent; $vevent3->DURATION = 'P1D'; $tests[] = [$vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $vevent4 = clone $vevent; $vevent4->DTSTART = '20111225'; $vevent4->DTSTART['VALUE'] = 'DATE'; $tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; // Event with no end date should be treated as lasting the entire day. $tests[] = [$vevent4, new \DateTime('2011-12-25 16:00:00'), new \DateTime('2011-12-25 17:00:00'), true]; // DTEND is non inclusive so all day events should not be returned on the next day. $tests[] = [$vevent4, new \DateTime('2011-12-26 00:00:00'), new \DateTime('2011-12-26 17:00:00'), false]; // The timezone of timerange in question also needs to be considered. $tests[] = [$vevent4, new \DateTime('2011-12-26 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2011-12-26 17:00:00', new \DateTimeZone('Europe/Berlin')), false]; $vevent5 = clone $vevent; $vevent5->DURATION = 'P1D'; $vevent5->RRULE = 'FREQ=YEARLY'; $tests[] = [$vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; $tests[] = [$vevent5, new \DateTime('2013-12-01'), new \DateTime('2013-12-31'), true]; $vevent6 = clone $vevent; $vevent6->DTSTART = '20111225'; $vevent6->DTSTART['VALUE'] = 'DATE'; $vevent6->DTEND = '20111225'; $vevent6->DTEND['VALUE'] = 'DATE'; $tests[] = [$vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true]; $tests[] = [$vevent6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; // Added this test to ensure that recurrence rules with no DTEND also // get checked for the entire day. $vevent7 = clone $vevent; $vevent7->DTSTART = '20120101'; $vevent7->DTSTART['VALUE'] = 'DATE'; $vevent7->RRULE = 'FREQ=MONTHLY'; $tests[] = [$vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true]; // The timezone of timerange in question should also be considered. $tests[] = [$vevent7, new \DateTime('2012-02-02 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2012-02-03 00:00:00', new \DateTimeZone('Europe/Berlin')), false]; // Added this test to check recurring events that have no instances. $vevent8 = clone $vevent; $vevent8->DTSTART = '20130329T140000'; $vevent8->DTEND = '20130329T153000'; $vevent8->RRULE = ['FREQ' => 'WEEKLY', 'BYDAY' => ['FR'], 'UNTIL' => '20130412T115959Z']; $vevent8->add('EXDATE', '20130405T140000'); $vevent8->add('EXDATE', '20130329T140000'); $tests[] = [$vevent8, new \DateTime('2013-03-01'), new \DateTime('2013-04-01'), false]; return $tests; }
private function split_message($message) { $data = null; $elem_data = array(); $data_list = array(); $elem_list = array(); if (empty($message)) { return; } //print "$message\n"; $lines = explode("\n", $message); foreach ($lines as $line) { $a = explode(":", $line); //print_r($a); $item = strtoupper($a[0]); if (count($a) > 2) { $elem = ''; for ($i = 1; $i < count($a); $i++) { if ($elem != '') { $elem .= ':'; } $elem .= $a[$i]; } //print "elem: $elem\n"; } else { $elem = $a[1]; } switch ($item) { case 'BEGIN': /*if (! in_array($elem, $this->elements)) { $found = TRUE; if (($sub = end($elem_list)) !== FALSE) { if (! array_key_exists($sub, $this->subelem)) $found = FALSE; } else $found = FALSE; reset($elem_list); if (! $found) break; }*/ if (count($data) > 0) { if (count($elem_list) > 0) { /*$name = array_pop($elem_list); if (array_key_exists($name, $this->subelem)) { print "BEGIN: $name\n"; print_r($data); }*/ $elem_data[array_pop($elem_list)] = $data; } else { $elem_data[$elem] = $data; } } array_push($elem_list, $elem); $data = array(); break; case 'END': if (count($elem_list) > 0) { /*$name = array_pop($elem_list); if (array_key_exists($name, $this->subelem)) { print "END: $name\n"; print_r($data); }*/ $elem_data[array_pop($elem_list)] = $data; } $data = array(); if ($elem == 'VCALENDAR' && count($elem_data) > 1) { array_push($data_list, $elem_data); $elem_data = array(); $elem_list = array(); } break; default: if (!is_array($data)) { throw new Exception("Message is not valid [missing 'BEGIN']"); } if (($pos = strpos($item, ';')) !== false) { $head = substr($item, 0, $pos); $elem = substr($item, $pos + 1) . ';' . $elem; $item = $head; //print "Ny elem: $item:$elem\n"; } $data[$item] = $elem; } } //print_r($data_list); foreach ($data_list as $item) { $c = $this->remove_value($item, 'VCALENDAR'); $calendar = new VCalendar($c); foreach ($item as $k => $v) { if ($k == 'DAYLIGHT' || $k == 'STANDARD') { $object = $calendar->getObject('VTimezone'); if (!is_object($object)) { $object = $this->newObject('VTimezone'); $calendar->addObject($object); } $object->setProperty($k, $v); } else { if (($object = $calendar->getObject($k)) == NULL) { $object = $this->newObject($k, $v); $calendar->addObject($object); } else { $object->setAllProperties($v); } } } array_push($this->items, $calendar); } }
function GetItip(VCalendar $vcal, $method, $attendee_value) { $iTIP = $vcal->GetItip($method, $attendee_value); $iTIP->AddProperty('REQUEST-STATUS', '2.0'); $components = $iTIP->GetComponents(); foreach ($components as $comp) { $properties = array(); foreach ($comp->GetProperties() as $k => $property) { switch ($property->Name()) { case 'DTSTART': case 'DTEND': case 'DUE': $when = new RepeatRuleDateTime($property); $properties[] = new vProperty($property->Name() . ":" . $when->UTC()); break; default: $properties[] = $property; } } $comp->SetProperties($properties); } return $iTIP; }