[Pkg-owncloud-commits] [php-sabre-vobject] 14/32: Reference timezone to expander and recurrence iterator.
David Prévot
taffit at moszumanska.debian.org
Fri Nov 28 22:27:09 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabre-vobject.
commit 0951c592be96af2d57ff57da9c5259f609b90a82
Author: Evert Pot <me at evertpot.com>
Date: Wed Nov 12 19:46:18 2014 -0500
Reference timezone to expander and recurrence iterator.
---
lib/Component/VCalendar.php | 21 ++++++++++++++-------
lib/DateTimeParser.php | 2 +-
lib/FreeBusyGenerator.php | 2 +-
lib/Recur/EventIterator.php | 31 ++++++++++++++++++++++++-------
lib/Recur/RRuleIterator.php | 6 +++++-
5 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/lib/Component/VCalendar.php b/lib/Component/VCalendar.php
index 01c165d..af837a0 100644
--- a/lib/Component/VCalendar.php
+++ b/lib/Component/VCalendar.php
@@ -2,10 +2,11 @@
namespace Sabre\VObject\Component;
-use
- Sabre\VObject,
- Sabre\VObject\Component,
- Sabre\VObject\Recur\EventIterator;
+use DateTime;
+use DateTimeZone;
+use Sabre\VObject;
+use Sabre\VObject\Component;
+use Sabre\VObject\Recur\EventIterator;
/**
* The VCalendar component
@@ -239,12 +240,18 @@ class VCalendar extends VObject\Document {
*
* @param DateTime $start
* @param DateTime $end
+ * @param DateTimeZone $timeZone reference timezone for floating dates and
+ * times.
* @return void
*/
- public function expand(\DateTime $start, \DateTime $end) {
+ public function expand(DateTime $start, DateTime $end, DateTimeZone $timeZone = null) {
$newEvents = array();
+ if (!$timeZone) {
+ $timeZone = new DateTimeZone('UTC');
+ }
+
foreach($this->select('VEVENT') as $key=>$vevent) {
if (isset($vevent->{'RECURRENCE-ID'})) {
@@ -288,11 +295,11 @@ class VCalendar extends VObject\Document {
foreach($newEvent->children as $child) {
if ($child instanceof VObject\Property\ICalendar\DateTime && $child->hasTime()) {
- $dt = $child->getDateTimes();
+ $dt = $child->getDateTimes($timeZone);
// We only need to update the first timezone, because
// setDateTimes will match all other timezones to the
// first.
- $dt[0]->setTimeZone(new \DateTimeZone('UTC'));
+ $dt[0]->setTimeZone(new DateTimeZone('UTC'));
$child->setDateTimes($dt);
}
diff --git a/lib/DateTimeParser.php b/lib/DateTimeParser.php
index 75aaa62..88a7982 100644
--- a/lib/DateTimeParser.php
+++ b/lib/DateTimeParser.php
@@ -185,7 +185,7 @@ class DateTimeParser {
} elseif (strlen($date)===8) {
return self::parseDate($date, $referenceTz);
} else {
- return self::parseDateTime($date, $referenceTZ);
+ return self::parseDateTime($date, $referenceTz);
}
}
diff --git a/lib/FreeBusyGenerator.php b/lib/FreeBusyGenerator.php
index a0f62c3..ef6e72a 100644
--- a/lib/FreeBusyGenerator.php
+++ b/lib/FreeBusyGenerator.php
@@ -205,7 +205,7 @@ class FreeBusyGenerator {
if ($component->RRULE) {
- $iterator = new EventIterator($object, (string)$component->uid);
+ $iterator = new EventIterator($object, (string)$component->uid, $this->timeZone);
if ($this->start) {
$iterator->fastForward($this->start);
}
diff --git a/lib/Recur/EventIterator.php b/lib/Recur/EventIterator.php
index 2ea55a4..8b14899 100644
--- a/lib/Recur/EventIterator.php
+++ b/lib/Recur/EventIterator.php
@@ -4,6 +4,7 @@ namespace Sabre\VObject\Recur;
use InvalidArgumentException;
use DateTime;
+use DateTimeZone;
use Sabre\VObject\Component;
use Sabre\VObject\Component\VEvent;
@@ -56,6 +57,13 @@ use Sabre\VObject\Component\VEvent;
class EventIterator implements \Iterator {
/**
+ * Reference timeZone for floating dates and times.
+ *
+ * @var DateTimeZone
+ */
+ protected $timeZone;
+
+ /**
* Creates the iterator
*
* You should pass a VCALENDAR component, as well as the UID of the event
@@ -63,8 +71,15 @@ class EventIterator implements \Iterator {
*
* @param Component $vcal
* @param string|null $uid
+ * @param DateTimeZone $timeZone Reference timezone for floating dates and
+ * times.
*/
- public function __construct(Component $vcal, $uid = null) {
+ public function __construct(Component $vcal, $uid = null, DateTimeZone $timeZone = null) {
+
+ if (is_null($this->timeZone)) {
+ $timeZone = new DateTimeZone('UTC');
+ }
+ $this->timeZone = $timeZone;
$rrule = null;
if ($vcal instanceof VEvent) {
@@ -95,7 +110,9 @@ class EventIterator implements \Iterator {
} else {
- $this->exceptions[$vevent->{'RECURRENCE-ID'}->getDateTime()->getTimeStamp()] = true;
+ $this->exceptions[
+ $vevent->{'RECURRENCE-ID'}->getDateTime($this->timeZone)->getTimeStamp()
+ ] = true;
$this->overriddenEvents[] = $vevent;
}
@@ -126,13 +143,13 @@ class EventIterator implements \Iterator {
'COUNT' => 1,
);
}
- $this->startDate = $this->masterEvent->DTSTART->getDateTime();
+ $this->startDate = $this->masterEvent->DTSTART->getDateTime($this->timeZone);
if (isset($this->masterEvent->EXDATE)) {
foreach($this->masterEvent->EXDATE as $exDate) {
- foreach($exDate->getDateTimes() as $dt) {
+ foreach($exDate->getDateTimes($this->timeZone) as $dt) {
$this->exceptions[$dt->getTimeStamp()] = true;
}
@@ -142,7 +159,7 @@ class EventIterator implements \Iterator {
if (isset($this->masterEvent->DTEND)) {
$this->eventDuration =
- $this->masterEvent->DTEND->getDateTime()->getTimeStamp() -
+ $this->masterEvent->DTEND->getDateTime($this->timeZone)->getTimeStamp() -
$this->startDate->getTimeStamp();
} elseif (isset($this->masterEvent->DURATION)) {
$duration = $this->masterEvent->DURATION->getDateInterval();
@@ -301,7 +318,7 @@ class EventIterator implements \Iterator {
// re-creating overridden event index.
$index = array();
foreach($this->overriddenEvents as $key=>$event) {
- $stamp = $event->DTSTART->getDateTime()->getTimeStamp();
+ $stamp = $event->DTSTART->getDateTime($this->timeZone)->getTimeStamp();
$index[$stamp] = $key;
}
krsort($index);
@@ -357,7 +374,7 @@ class EventIterator implements \Iterator {
// Putting the rrule next date aside.
$this->nextDate = $nextDate;
- $this->currentDate = $this->currentOverriddenEvent->DTSTART->getDateTime();
+ $this->currentDate = $this->currentOverriddenEvent->DTSTART->getDateTime($this->timeZone);
// Ensuring that this item will only be used once.
array_pop($this->overriddenEventsIndex);
diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php
index ba882d7..08f2010 100644
--- a/lib/Recur/RRuleIterator.php
+++ b/lib/Recur/RRuleIterator.php
@@ -374,7 +374,11 @@ class RRuleIterator implements Iterator {
// Current hour of the day
$currentHour = $this->currentDate->format('G');
- } while (($this->byDay && !in_array($currentDay, $recurrenceDays)) || ($this->byHour && !in_array($currentHour, $recurrenceHours)) || ($this->byMonth && !in_array($currentMonth, $recurrenceMonths)));
+ } while (
+ ($this->byDay && !in_array($currentDay, $recurrenceDays)) ||
+ ($this->byHour && !in_array($currentHour, $recurrenceHours)) ||
+ ($this->byMonth && !in_array($currentMonth, $recurrenceMonths))
+ );
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git
More information about the Pkg-owncloud-commits
mailing list