/** * Constructs a new SG_iCal_VEvent. Needs the SG_iCalReader * supplied so it can query for timezones. * @param SG_iCal_Line[] $data * @param SG_iCalReader $ical */ public function __construct($data, SG_iCal $ical) { $this->uid = $data['uid']->getData(); unset($data['uid']); if (isset($data['rrule'])) { $this->recurrence = new SG_iCal_Recurrence($data['rrule']); unset($data['rrule']); } if (isset($data['dtstart'])) { $this->start = $this->getTimestamp($data['dtstart'], $ical); unset($data['dtstart']); } if (isset($data['dtend'])) { $this->end = $this->getTimestamp($data['dtend'], $ical); unset($data['dtend']); } elseif (isset($data['duration'])) { require_once dirname(__FILE__) . '/../helpers/SG_iCal_Duration.php'; // BUILD: Remove line $dur = new SG_iCal_Duration($data['duration']->getData()); $this->end = $this->start + $dur->getDuration(); unset($data['duration']); } elseif (isset($this->recurrence)) { //if there is a recurrence rule $until = $this->recurrence->getUntil(); $count = $this->recurrence->getCount(); //check if there is either 'until' or 'count' set if ($this->recurrence->getUntil() or $this->recurrence->getCount()) { //if until is set, set that as the end date (using getTimeStamp) if ($until) { $this->end = strtotime($until); } //if count is set, then figure out the last occurrence and set that as the end date } } $imports = array('summary', 'description', 'location'); foreach ($imports as $import) { if (isset($data[$import])) { $this->{$import} = $data[$import]->getData(); unset($data[$import]); } } $this->data = SG_iCal_Line::Remove_Line($data); }
public function testDurationNegative() { //A duration of -1 day $dur = new SG_iCal_Duration('-P1D'); $this->assertEquals(-1 * $this->secsDay, $dur->getDuration()); }
/** * Constructs a new SG_iCal_VEvent. Needs the SG_iCalReader * supplied so it can query for timezones. * @param SG_iCal_Line[] $data * @param SG_iCalReader $ical */ public function __construct($data, SG_iCal $ical) { $this->uid = $data['uid']->getData(); unset($data['uid']); if (isset($data['rrule'])) { $this->recurrence = new SG_iCal_Recurrence($data['rrule']); unset($data['rrule']); } if (isset($data['exrule'])) { $this->recurex = new SG_iCal_Recurrence($data['exrule']); unset($data['exrule']); } if (isset($data['dtstart'])) { $this->start = $this->getTimestamp($data['dtstart'], $ical); unset($data['dtstart']); } if (isset($data['dtend'])) { $this->end = $this->getTimestamp($data['dtend'], $ical); unset($data['dtend']); } elseif (isset($data['duration'])) { $dur = new SG_iCal_Duration($data['duration']->getData()); $this->end = $this->start + $dur->getDuration(); unset($data['duration']); } //google cal set dtend as end of initial event (duration) if (isset($this->recurrence)) { //if there is a recurrence rule //exclusions if (isset($data['exdate'])) { foreach ($data['exdate'] as $exdate) { foreach ($exdate->getDataAsArray() as $ts) { $this->excluded[] = strtotime($ts); } } unset($data['exdate']); } //additions if (isset($data['rdate'])) { foreach ($data['rdate'] as $rdate) { foreach ($rdate->getDataAsArray() as $ts) { $this->added[] = strtotime($ts); } } unset($data['rdate']); } $until = $this->recurrence->getUntil(); $count = $this->recurrence->getCount(); //check if there is either 'until' or 'count' set if ($until) { //ok.. } elseif ($count) { //if count is set, then figure out the last occurrence and set that as the end date $this->getFrequency(); $until = $this->freq->lastOccurrence($this->start); } else { //forever... limit to 3 years $this->recurrence->setUntil('+3 years'); $until = $this->recurrence->getUntil(); } //date_default_timezone_set( xx ) needed ?; $this->laststart = strtotime($until); $this->lastend = $this->laststart + $this->getDuration(); } $imports = array('summary', 'description', 'location'); foreach ($imports as $import) { if (isset($data[$import])) { $this->{$import} = $data[$import]->getData(); unset($data[$import]); } } if (isset($this->previous_tz)) { date_default_timezone_set($this->previous_tz); } $this->data = SG_iCal_Line::Remove_Line($data); }