[Pkg-owncloud-commits] [php-sabre-vobject] 31/341: Merge branch '3.3'
David Prévot
taffit at moszumanska.debian.org
Tue Aug 11 13:35:29 UTC 2015
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 04f01385313afd55c12150844aeca4d2533137c0
Merge: 842ee5d 9b61b8f
Author: Evert Pot <me at evertpot.com>
Date: Thu Nov 13 15:22:07 2014 -0500
Merge branch '3.3'
Conflicts:
lib/Component/VCalendar.php
lib/DateTimeParser.php
lib/FreeBusyGenerator.php
lib/Property/ICalendar/DateTime.php
lib/Recur/EventIterator.php
tests/VObject/FreeBusyGeneratorTest.php
ChangeLog.md | 5 +
lib/Component/VCalendar.php | 15 +-
lib/DateTimeParser.php | 40 ++--
lib/FreeBusyGenerator.php | 42 +++-
lib/Property/ICalendar/DateTime.php | 29 ++-
lib/Recur/EventIterator.php | 65 +++++-
lib/Recur/RRuleIterator.php | 6 +-
tests/VObject/Component/VCalendarTest.php | 56 ++++-
tests/VObject/FreeBusyGeneratorTest.php | 247 +++++++++++++++------
tests/VObject/Property/ICalendar/DateTimeTest.php | 39 +++-
.../Recur/EventIterator/IncorrectExpandTest.php | 1 -
.../Recur/EventIterator/MissingOverriddenTest.php | 1 -
12 files changed, 423 insertions(+), 123 deletions(-)
diff --cc lib/Component/VCalendar.php
index 0a07594,8704d33..501ba87
--- a/lib/Component/VCalendar.php
+++ b/lib/Component/VCalendar.php
@@@ -2,7 -2,8 +2,8 @@@
namespace Sabre\VObject\Component;
-use DateTime;
+use DateTimeInterface;
+ use DateTimeZone;
use Sabre\VObject;
use Sabre\VObject\Component;
use Sabre\VObject\Recur\EventIterator;
@@@ -237,14 -238,20 +238,20 @@@ class VCalendar extends VObject\Documen
* possible for clients to request expand events, if they are rather simple
* clients and do not have the possibility to calculate recurrences.
*
- * @param DateTime $start
- * @param DateTime $end
+ * @param DateTimeInterface $start
+ * @param DateTimeInterface $end
+ * @param DateTimeZone $timeZone reference timezone for floating dates and
+ * times.
* @return void
*/
- function expand(DateTimeInterface $start, DateTimeInterface $end) {
- public function expand(DateTime $start, DateTime $end, DateTimeZone $timeZone = null) {
++ function expand(DateTimeInterface $start, DateTimeInterface $end, DateTimeZone $timeZone = null) {
- $newEvents = array();
+ $newEvents = [];
+ if (!$timeZone) {
+ $timeZone = new DateTimeZone('UTC');
+ }
+
foreach($this->select('VEVENT') as $key=>$vevent) {
if (isset($vevent->{'RECURRENCE-ID'})) {
@@@ -292,7 -299,7 +299,7 @@@
// We only need to update the first timezone, because
// setDateTimes will match all other timezones to the
// first.
- $dt[0] = $dt[0]->setTimeZone(new \DateTimeZone('UTC'));
- $dt[0]->setTimeZone(new DateTimeZone('UTC'));
++ $dt[0] = $dt[0]->setTimeZone(new DateTimeZone('UTC'));
$child->setDateTimes($dt);
}
diff --cc lib/DateTimeParser.php
index 25360e8,88a7982..7d0a952
--- a/lib/DateTimeParser.php
+++ b/lib/DateTimeParser.php
@@@ -2,7 -2,11 +2,11 @@@
namespace Sabre\VObject;
-use DateTime;
+use DateTimeImmutable;
+ use DateTimeZone;
+ use DateInterval;
+ use InvalidArgumentException;
+ use LogicException;
/**
* DateTimeParser
@@@ -26,9 -29,9 +30,9 @@@ class DateTimeParser
*
* @param string $dt
* @param DateTimeZone $tz
- * @return DateTime
+ * @return DateTimeImmutable
*/
- static function parseDateTime($dt, \DateTimeZone $tz = null) {
- static public function parseDateTime($dt, DateTimeZone $tz = null) {
++ static function parseDateTime($dt, DateTimeZone $tz = null) {
// Format is YYYYMMDD + "T" + hhmmss
$result = preg_match('/^([0-9]{4})([0-1][0-9])([0-3][0-9])T([0-2][0-9])([0-5][0-9])([0-5][0-9])([Z]?)$/',$dt,$matches);
@@@ -38,32 -41,37 +42,36 @@@
}
if ($matches[7]==='Z' || is_null($tz)) {
- $tz = new \DateTimeZone('UTC');
+ $tz = new DateTimeZone('UTC');
}
- $date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] .':' . $matches[6], $tz);
+ $date = new DateTimeImmutable($matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] .':' . $matches[6], $tz);
-- // Still resetting the timezone, to normalize everything to UTC
-- // $date->setTimeZone(new \DateTimeZone('UTC'));
return $date;
}
/**
- * Parses an iCalendar (rfc5545) formatted date and returns a DateTime object.
+ * Parses an iCalendar (rfc5545) formatted date and returns a DateTimeImmutable object
*
* @param string $date
+ * @param DateTimeZone $tz
- * @return DateTime
+ * @return DateTimeImmutable
*/
- static function parseDate($date) {
- static public function parseDate($date, DateTimeZone $tz = null) {
++ static function parseDate($date, DateTimeZone $tz = null) {
// Format is YYYYMMDD
$result = preg_match('/^([0-9]{4})([0-1][0-9])([0-3][0-9])$/',$date,$matches);
if (!$result) {
- throw new \LogicException('The supplied iCalendar date value is incorrect: ' . $date);
+ throw new LogicException('The supplied iCalendar date value is incorrect: ' . $date);
+ }
+
+ if (is_null($tz)) {
+ $tz = new DateTimeZone('UTC');
}
- $date = new DateTimeImmutable($matches[1] . '-' . $matches[2] . '-' . $matches[3], new \DateTimeZone('UTC'));
- $date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3], $tz);
++ $date = new DateTimeImmutable($matches[1] . '-' . $matches[2] . '-' . $matches[3], $tz);
++
return $date;
}
@@@ -167,10 -175,10 +175,10 @@@
* Parses either a Date or DateTime, or Duration value.
*
* @param string $date
- * @param DateTimeZone|string $referenceTZ
+ * @param DateTimeZone|string $referenceTz
- * @return DateTime|DateInterval
+ * @return DateTimeImmutable|DateInterval
*/
- static function parse($date, $referenceTZ = null) {
- static public function parse($date, $referenceTz = null) {
++ static function parse($date, $referenceTz = null) {
if ($date[0]==='P' || ($date[0]==='-' && $date[1]==='P')) {
return self::parseDuration($date);
diff --cc lib/FreeBusyGenerator.php
index 043bdf3,ef6e72a..38fe61a
--- a/lib/FreeBusyGenerator.php
+++ b/lib/FreeBusyGenerator.php
@@@ -2,8 -2,7 +2,9 @@@
namespace Sabre\VObject;
+use DateTimeInterface;
+use DateTimeImmutable;
+ use DateTimeZone;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Recur\EventIterator;
@@@ -57,12 -71,13 +73,12 @@@ class FreeBusyGenerator
* Check the setTimeRange and setObjects methods for details about the
* arguments.
*
- * @param DateTime $start
- * @param DateTime $end
+ * @param DateTimeInterface $start
+ * @param DateTimeInterface $end
* @param mixed $objects
- * @return void
+ * @param DateTimeZone $timeZone
- * @return void
*/
- function __construct(DateTimeInterface $start = null, DateTimeInterface $end = null, $objects = null) {
- public function __construct(\DateTime $start = null, \DateTime $end = null, $objects = null, DateTimeZone $timeZone = null) {
++ function __construct(DateTimeInterface $start = null, DateTimeInterface $end = null, $objects = null, DateTimeZone $timeZone = null) {
if ($start && $end) {
$this->setTimeRange($start, $end);
diff --cc lib/Property/ICalendar/DateTime.php
index ba454ac,5e7eb59..97ffe9f
--- a/lib/Property/ICalendar/DateTime.php
+++ b/lib/Property/ICalendar/DateTime.php
@@@ -2,8 -2,9 +2,10 @@@
namespace Sabre\VObject\Property\ICalendar;
+use DateTimeInterface;
+ use DateTimeZone;
use Sabre\VObject\Property;
+ use Sabre\VObject\Parser\MimeDir;
use Sabre\VObject\DateTimeParser;
use Sabre\VObject\TimeZoneUtil;
@@@ -116,11 -117,16 +118,16 @@@ class DateTime extends Property
* first will be returned. To get an array with multiple values, call
* getDateTimes.
*
+ * If no timezone information is known, because it's either an all-day
+ * property or floating time, we will use the DateTimeZone argument to
+ * figure out the exact date.
+ *
+ * @param DateTimeZone $timeZone
- * @return \DateTime
+ * @return DateTimeImmutable
*/
- function getDateTime() {
- public function getDateTime(DateTimeZone $timeZone = null) {
++ function getDateTime(DateTimeZone $timeZone = null) {
- $dt = $this->getDateTimes();
+ $dt = $this->getDateTimes($timeZone);
if (!$dt) return null;
return $dt[0];
@@@ -130,20 -136,25 +137,26 @@@
/**
* Returns multiple date-time values.
*
+ * If no timezone information is known, because it's either an all-day
+ * property or floating time, we will use the DateTimeZone argument to
+ * figure out the exact date.
+ *
+ * @param DateTimeZone $timeZone
+ * @return DateTimeImmutable[]
+ * @return \DateTime[]
*/
- function getDateTimes() {
- public function getDateTimes(DateTimeZone $timeZone = null) {
++ function getDateTimes(DateTimeZone $timeZone = null) {
- // Finding the timezone.
- $tz = $this['TZID'];
+ // Does the property have a TZID?
+ $tzid = $this['TZID'];
- if ($tz) {
- $tz = TimeZoneUtil::getTimeZone((string)$tz, $this->root);
+ if ($tzid) {
+ $timeZone = TimeZoneUtil::getTimeZone((string)$tzid, $this->root);
}
- $dts = array();
+ $dts = [];
foreach($this->getParts() as $part) {
- $dts[] = DateTimeParser::parse($part, $tz);
+ $dts[] = DateTimeParser::parse($part, $timeZone);
}
return $dts;
diff --cc lib/Recur/EventIterator.php
index d0cc2ad,8743f5a..235685f
--- a/lib/Recur/EventIterator.php
+++ b/lib/Recur/EventIterator.php
@@@ -2,9 -2,9 +2,10 @@@
namespace Sabre\VObject\Recur;
--use InvalidArgumentException;
-use DateTime;
+ use DateTimeZone;
+use DateTimeImmutable;
+use DateTimeInterface;
++use InvalidArgumentException;
use Sabre\VObject\Component;
use Sabre\VObject\Component\VEvent;
@@@ -64,12 -78,20 +79,19 @@@ class EventIterator implements \Iterato
*
* @param Component $vcal
* @param string|null $uid
+ * @param DateTimeZone $timeZone Reference timezone for floating dates and
+ * times.
*/
- function __construct(Component $vcal, $uid = null) {
- public function __construct(Component $vcal, $uid = null, DateTimeZone $timeZone = null) {
++ 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) {
// Single instance mode.
- $events = array($vcal);
+ $events = [$vcal];
} else {
$uid = (string)$uid;
if (!$uid) {
@@@ -136,9 -172,9 +172,9 @@@
} elseif (isset($this->masterEvent->DURATION)) {
$duration = $this->masterEvent->DURATION->getDateInterval();
$end = clone $this->startDate;
- $end->add($duration);
+ $end = $end->add($duration);
$this->eventDuration = $end->getTimeStamp() - $this->startDate->getTimeStamp();
- } elseif ($this->masterEvent->DTSTART->getValueType() === 'DATE') {
+ } elseif ($this->allDay) {
$this->eventDuration = 3600 * 24;
} else {
$this->eventDuration = 0;
@@@ -287,9 -331,9 +330,9 @@@
$this->recurIterator->rewind();
// re-creating overridden event index.
- $index = array();
+ $index = [];
foreach($this->overriddenEvents as $key=>$event) {
- $stamp = $event->DTSTART->getDateTime()->getTimeStamp();
+ $stamp = $event->DTSTART->getDateTime($this->timeZone)->getTimeStamp();
$index[$stamp] = $key;
}
krsort($index);
diff --cc tests/VObject/Property/ICalendar/DateTimeTest.php
index ffa4194,c7ddfb8..bf36a5c
--- a/tests/VObject/Property/ICalendar/DateTimeTest.php
+++ b/tests/VObject/Property/ICalendar/DateTimeTest.php
@@@ -197,8 -197,20 +197,20 @@@ class DateTimeTest extends \PHPUnit_Fra
}
+ function testGetDateTimeDateDATEReferenceTimeZone() {
+
+ $elem = $this->vcal->createProperty('DTSTART','19850704');
+
+ $tz = new \DateTimeZone('America/Toronto');
+ $dt = $elem->getDateTime($tz);
- $dt->setTimeZone(new \DateTimeZone('UTC'));
++ $dt = $dt->setTimeZone(new \DateTimeZone('UTC'));
+
- $this->assertInstanceOf('DateTime', $dt);
++ $this->assertInstanceOf('DateTimeImmutable', $dt);
+ $this->assertEquals('1985-07-04 04:00:00', $dt->format('Y-m-d H:i:s'));
+
+ }
- function testGetDateTimeDateLOCAL() {
+ function testGetDateTimeDateFloating() {
$elem = $this->vcal->createProperty('DTSTART','19850704T013000');
$dt = $elem->getDateTime();
@@@ -208,6 -220,19 +220,19 @@@
}
+ function testGetDateTimeDateFloatingReferenceTimeZone() {
+
+ $elem = $this->vcal->createProperty('DTSTART','19850704T013000');
+
+ $tz = new \DateTimeZone('America/Toronto');
+ $dt = $elem->getDateTime($tz);
- $dt->setTimeZone(new \DateTimeZone('UTC'));
++ $dt = $dt->setTimeZone(new \DateTimeZone('UTC'));
+
- $this->assertInstanceOf('DateTime', $dt);
++ $this->assertInstanceOf('DateTimeInterface', $dt);
+ $this->assertEquals('1985-07-04 05:30:00', $dt->format('Y-m-d H:i:s'));
+
+ }
+
function testGetDateTimeDateUTC() {
$elem = $this->vcal->createProperty('DTSTART','19850704T013000Z');
--
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