public function render()
{
if (true === isset($this->arguments['start']) && false === empty($this->arguments['start'])) {
$start = $this->arguments['start'];
} else {
$start = 'now';
}
$startDateTime = $this->enforceDateTime($start);
if (true === isset($this->arguments['end']) && false === empty($this->arguments['end'])) {
$endDateTime = $this->enforceDateTime($this->arguments['end']);
} else {
$endDateTime = null;
}
if (true === isset($this->arguments['intervalFormat']) && false === empty($this->arguments['intervalFormat'])) {
$intervalFormat = $this->arguments['intervalFormat'];
}
if (null === $intervalFormat && null === $endDateTime) {
throw new Exception('Either end or intervalFormat has to be provided.', 1369573110);
}
if (true === isset($intervalFormat) && null !== $intervalFormat) {
try {
$interval = new \DateInterval($intervalFormat);
} catch (\Exception $exception) {
throw new Exception('"' . $intervalFormat . '" could not be parsed by \\DateInterval constructor.', 1369573111);
}
} else {
$interval = $endDateTime->diff($startDateTime);
}
if (null !== $interval && null === $endDateTime) {
$endDateTime = new \DateTime();
$endDateTime->add($endDateTime->diff($startDateTime));
$endDateTime->add($interval);
}
$return = $this->arguments['return'];
if (null === $return) {
$spaceGlue = (bool) $this->arguments['spaceGlue'];
$glue = strval($this->arguments['glue']);
$startFormat = $this->arguments['format'];
$endFormat = $this->arguments['format'];
if (null !== $this->arguments['startFormat'] && false === empty($this->arguments['startFormat'])) {
$startFormat = $this->arguments['startFormat'];
}
if (null !== $this->arguments['endFormat'] && false === empty($this->arguments['endFormat'])) {
$endFormat = $this->arguments['endFormat'];
}
$output = $this->formatDate($startDateTime, $startFormat);
$output .= true === $spaceGlue ? ' ' : '';
$output .= $glue;
$output .= true === $spaceGlue ? ' ' : '';
$output .= $this->formatDate($endDateTime, $endFormat);
} elseif ('DateTime' === $return) {
$output = $endDateTime;
} elseif (true === is_string($return)) {
if (false === strpos($return, '%')) {
$return = '%' . $return;
}
$output = $interval->format($return);
} elseif (true === is_array($return)) {
$output = [];
foreach ($return as $format) {
if (false === strpos($format, '%')) {
$format = '%' . $format;
}
array_push($output, $interval->format($format));
}
}
return $output;
}