aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php')
-rw-r--r--vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php122
1 files changed, 44 insertions, 78 deletions
diff --git a/vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php b/vendor/sabre/vobject/lib/Property/VCard/DateAndOrTime.php
index 3b4ae3bb5..b7e17492a 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 null|string
+ * @var string|null
*/
public $delimiter = null;
@@ -36,10 +36,9 @@ class DateAndOrTime extends Property {
*
* @return string
*/
- function getValueType() {
-
+ public function getValueType()
+ {
return 'DATE-AND-OR-TIME';
-
}
/**
@@ -48,11 +47,9 @@ class DateAndOrTime extends Property {
* You may also specify DateTimeInterface objects here.
*
* @param array $parts
- *
- * @return void
*/
- function setParts(array $parts) {
-
+ public function setParts(array $parts)
+ {
if (count($parts) > 1) {
throw new \InvalidArgumentException('Only one value allowed');
}
@@ -61,7 +58,6 @@ class DateAndOrTime extends Property {
} else {
parent::setParts($parts);
}
-
}
/**
@@ -72,28 +68,23 @@ class DateAndOrTime extends Property {
* Instead of strings, you may also use DateTimeInterface here.
*
* @param string|array|DateTimeInterface $value
- *
- * @return void
*/
- function setValue($value) {
-
+ public 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
*/
- function setDateTime(DateTimeInterface $dt) {
-
+ public function setDateTime(DateTimeInterface $dt)
+ {
$tz = $dt->getTimeZone();
$isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']);
@@ -105,7 +96,6 @@ class DateAndOrTime extends Property {
}
$this->value = $value;
-
}
/**
@@ -124,12 +114,12 @@ class DateAndOrTime extends Property {
*
* @return DateTimeImmutable
*/
- function getDateTime() {
-
+ public function getDateTime()
+ {
$now = new DateTime();
- $tzFormat = $now->getTimezone()->getOffset($now) === 0 ? '\\Z' : 'O';
- $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This' . $tzFormat));
+ $tzFormat = 0 === $now->getTimezone()->getOffset($now) ? '\\Z' : 'O';
+ $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This'.$tzFormat));
$dateParts = DateTimeParser::parseVCardDateTime($this->getValue());
@@ -141,8 +131,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]");
+ return new DateTimeImmutable("$dateParts[year]-$dateParts[month]-$dateParts[date] $dateParts[hour]:$dateParts[minute]:$dateParts[second] $dateParts[timezone]");
}
/**
@@ -152,15 +142,14 @@ class DateAndOrTime extends Property {
*
* @return array
*/
- function getJsonValue() {
-
+ public function getJsonValue()
+ {
$parts = DateTimeParser::parseVCardDateTime($this->getValue());
$dateStr = '';
// Year
if (!is_null($parts['year'])) {
-
$dateStr .= $parts['year'];
if (!is_null($parts['month'])) {
@@ -168,26 +157,21 @@ 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'
@@ -199,7 +183,6 @@ 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];
@@ -209,13 +192,11 @@ 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.
@@ -224,13 +205,11 @@ 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 .= '-';
@@ -247,30 +226,27 @@ 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.
- *
- * @return void
+ * @param Xml\Writer $writer XML writer
*/
- 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];
};
@@ -282,31 +258,29 @@ 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');
@@ -317,22 +291,19 @@ 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);
-
}
/**
@@ -342,13 +313,10 @@ class DateAndOrTime extends Property {
* not yet done, but parameters are not included.
*
* @param string $val
- *
- * @return void
*/
- function setRawMimeDirValue($val) {
-
+ public function setRawMimeDirValue($val)
+ {
$this->setValue($val);
-
}
/**
@@ -356,10 +324,9 @@ class DateAndOrTime extends Property {
*
* @return string
*/
- function getRawMimeDirValue() {
-
+ public function getRawMimeDirValue()
+ {
return implode($this->delimiter, $this->getParts());
-
}
/**
@@ -384,8 +351,8 @@ class DateAndOrTime extends Property {
*
* @return array
*/
- function validate($options = 0) {
-
+ public function validate($options = 0)
+ {
$messages = parent::validate($options);
$value = $this->getValue();
@@ -393,13 +360,12 @@ 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;
-
}
}