From f1c07977809ce3221286d53e99f0d91145b1166f Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 25 Apr 2019 11:24:09 +0200 Subject: Revert "update composer libs" This reverts commit e779335d060b3a51d6a144d23af4097ae6801473 --- .../vobject/lib/Property/VCard/DateAndOrTime.php | 122 +++++++++++++-------- 1 file changed, 78 insertions(+), 44 deletions(-) (limited to 'vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php') diff --git a/vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php b/vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php index b7e17492a..3b4ae3bb5 100644 --- a/vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php +++ b/vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php @@ -19,12 +19,12 @@ use Sabre\Xml; * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class DateAndOrTime extends Property -{ +class DateAndOrTime extends Property { + /** * Field separator. * - * @var string|null + * @var null|string */ public $delimiter = null; @@ -36,9 +36,10 @@ class DateAndOrTime extends Property * * @return string */ - public function getValueType() - { + function getValueType() { + return 'DATE-AND-OR-TIME'; + } /** @@ -47,9 +48,11 @@ class DateAndOrTime extends Property * You may also specify DateTimeInterface objects here. * * @param array $parts + * + * @return void */ - public function setParts(array $parts) - { + function setParts(array $parts) { + if (count($parts) > 1) { throw new \InvalidArgumentException('Only one value allowed'); } @@ -58,6 +61,7 @@ class DateAndOrTime extends Property } else { parent::setParts($parts); } + } /** @@ -68,23 +72,28 @@ class DateAndOrTime extends Property * Instead of strings, you may also use DateTimeInterface here. * * @param string|array|DateTimeInterface $value + * + * @return void */ - public function setValue($value) - { + function setValue($value) { + if ($value instanceof DateTimeInterface) { $this->setDateTime($value); } else { parent::setValue($value); } + } /** * Sets the property as a DateTime object. * * @param DateTimeInterface $dt + * + * @return void */ - public function setDateTime(DateTimeInterface $dt) - { + function setDateTime(DateTimeInterface $dt) { + $tz = $dt->getTimeZone(); $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']); @@ -96,6 +105,7 @@ class DateAndOrTime extends Property } $this->value = $value; + } /** @@ -114,12 +124,12 @@ class DateAndOrTime extends Property * * @return DateTimeImmutable */ - public function getDateTime() - { + function getDateTime() { + $now = new DateTime(); - $tzFormat = 0 === $now->getTimezone()->getOffset($now) ? '\\Z' : 'O'; - $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This'.$tzFormat)); + $tzFormat = $now->getTimezone()->getOffset($now) === 0 ? '\\Z' : 'O'; + $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This' . $tzFormat)); $dateParts = DateTimeParser::parseVCardDateTime($this->getValue()); @@ -131,8 +141,8 @@ class DateAndOrTime extends Property $dateParts[$k] = $nowParts[$k]; } } - return new DateTimeImmutable("$dateParts[year]-$dateParts[month]-$dateParts[date] $dateParts[hour]:$dateParts[minute]:$dateParts[second] $dateParts[timezone]"); + } /** @@ -142,14 +152,15 @@ class DateAndOrTime extends Property * * @return array */ - public function getJsonValue() - { + function getJsonValue() { + $parts = DateTimeParser::parseVCardDateTime($this->getValue()); $dateStr = ''; // Year if (!is_null($parts['year'])) { + $dateStr .= $parts['year']; if (!is_null($parts['month'])) { @@ -157,21 +168,26 @@ class DateAndOrTime extends Property // dash. $dateStr .= '-'; } + } else { + if (!is_null($parts['month']) || !is_null($parts['date'])) { // Inserting two dashes $dateStr .= '--'; } + } // Month if (!is_null($parts['month'])) { + $dateStr .= $parts['month']; if (isset($parts['date'])) { // If month and date are set, we need the separator dash. $dateStr .= '-'; } + } elseif (isset($parts['date'])) { // If the month is empty, and a date is set, we need a 'empty // dash' @@ -183,6 +199,7 @@ class DateAndOrTime extends Property $dateStr .= $parts['date']; } + // Early exit if we don't have a time string. if (is_null($parts['hour']) && is_null($parts['minute']) && is_null($parts['second'])) { return [$dateStr]; @@ -192,11 +209,13 @@ class DateAndOrTime extends Property // Hour if (!is_null($parts['hour'])) { + $dateStr .= $parts['hour']; if (!is_null($parts['minute'])) { $dateStr .= ':'; } + } else { // We know either minute or second _must_ be set, so we insert a // dash for an empty value. @@ -205,11 +224,13 @@ class DateAndOrTime extends Property // Minute if (!is_null($parts['minute'])) { + $dateStr .= $parts['minute']; if (!is_null($parts['second'])) { $dateStr .= ':'; } + } elseif (isset($parts['second'])) { // Dash for empty minute $dateStr .= '-'; @@ -226,27 +247,30 @@ class DateAndOrTime extends Property } return [$dateStr]; + } /** * This method serializes only the value of a property. This is used to * create xCard or xCal documents. * - * @param Xml\Writer $writer XML writer + * @param Xml\Writer $writer XML writer. + * + * @return void */ - protected function xmlSerializeValue(Xml\Writer $writer) - { + protected function xmlSerializeValue(Xml\Writer $writer) { + $valueType = strtolower($this->getValueType()); $parts = DateTimeParser::parseVCardDateAndOrTime($this->getValue()); $value = ''; // $d = defined - $d = function ($part) use ($parts) { + $d = function($part) use ($parts) { return !is_null($parts[$part]); }; // $r = read - $r = function ($part) use ($parts) { + $r = function($part) use ($parts) { return $parts[$part]; }; @@ -258,29 +282,31 @@ class DateAndOrTime extends Property // } if (($d('year') || $d('month') || $d('date')) && (!$d('hour') && !$d('minute') && !$d('second') && !$d('timezone'))) { + if ($d('year') && $d('month') && $d('date')) { - $value .= $r('year').$r('month').$r('date'); + $value .= $r('year') . $r('month') . $r('date'); } elseif ($d('year') && $d('month') && !$d('date')) { - $value .= $r('year').'-'.$r('month'); + $value .= $r('year') . '-' . $r('month'); } elseif (!$d('year') && $d('month')) { - $value .= '--'.$r('month').$r('date'); + $value .= '--' . $r('month') . $r('date'); } elseif (!$d('year') && !$d('month') && $d('date')) { - $value .= '---'.$r('date'); + $value .= '---' . $r('date'); } - // # 4.3.2 + // # 4.3.2 // value-time = element time { // xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)" // ~ "(Z|[+\-]\d\d(\d\d)?)?" } // } } elseif ((!$d('year') && !$d('month') && !$d('date')) && ($d('hour') || $d('minute') || $d('second'))) { + if ($d('hour')) { - $value .= $r('hour').$r('minute').$r('second'); + $value .= $r('hour') . $r('minute') . $r('second'); } elseif ($d('minute')) { - $value .= '-'.$r('minute').$r('second'); + $value .= '-' . $r('minute') . $r('second'); } elseif ($d('second')) { - $value .= '--'.$r('second'); + $value .= '--' . $r('second'); } $value .= $r('timezone'); @@ -291,19 +317,22 @@ class DateAndOrTime extends Property // ~ "(Z|[+\-]\d\d(\d\d)?)?" } // } } elseif ($d('date') && $d('hour')) { + if ($d('year') && $d('month') && $d('date')) { - $value .= $r('year').$r('month').$r('date'); + $value .= $r('year') . $r('month') . $r('date'); } elseif (!$d('year') && $d('month') && $d('date')) { - $value .= '--'.$r('month').$r('date'); + $value .= '--' . $r('month') . $r('date'); } elseif (!$d('year') && !$d('month') && $d('date')) { - $value .= '---'.$r('date'); + $value .= '---' . $r('date'); } - $value .= 'T'.$r('hour').$r('minute').$r('second'). + $value .= 'T' . $r('hour') . $r('minute') . $r('second') . $r('timezone'); + } $writer->writeElement($valueType, $value); + } /** @@ -313,10 +342,13 @@ class DateAndOrTime extends Property * not yet done, but parameters are not included. * * @param string $val + * + * @return void */ - public function setRawMimeDirValue($val) - { + function setRawMimeDirValue($val) { + $this->setValue($val); + } /** @@ -324,9 +356,10 @@ class DateAndOrTime extends Property * * @return string */ - public function getRawMimeDirValue() - { + function getRawMimeDirValue() { + return implode($this->delimiter, $this->getParts()); + } /** @@ -351,8 +384,8 @@ class DateAndOrTime extends Property * * @return array */ - public function validate($options = 0) - { + function validate($options = 0) { + $messages = parent::validate($options); $value = $this->getValue(); @@ -360,12 +393,13 @@ class DateAndOrTime extends Property DateTimeParser::parseVCardDateTime($value); } catch (InvalidDataException $e) { $messages[] = [ - 'level' => 3, - 'message' => 'The supplied value ('.$value.') is not a correct DATE-AND-OR-TIME property', - 'node' => $this, + 'level' => 3, + 'message' => 'The supplied value (' . $value . ') is not a correct DATE-AND-OR-TIME property', + 'node' => $this, ]; } return $messages; + } } -- cgit v1.2.3