From f968984feb77f540656790a335e882cef1c9a036 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 19 May 2015 12:46:08 +0200 Subject: [PATCH] Drop the DateTimeRenderer refs #6778 --- library/Icinga/Web/View/DateTimeRenderer.php | 204 ------------------- 1 file changed, 204 deletions(-) delete mode 100644 library/Icinga/Web/View/DateTimeRenderer.php diff --git a/library/Icinga/Web/View/DateTimeRenderer.php b/library/Icinga/Web/View/DateTimeRenderer.php deleted file mode 100644 index 058f07ad8..000000000 --- a/library/Icinga/Web/View/DateTimeRenderer.php +++ /dev/null @@ -1,204 +0,0 @@ -future = $future; - $this->now = new DateTime(); - $this->dateTime = $this->normalize($dateTime); - $this->detectType(); - } - - /** - * Creates a new DateTimeRenderer - * - * @param DateTime|int $dateTime - * @param bool $future - * - * @return DateTimeRenderer - */ - public static function create($dateTime, $future = false) - { - return new static($dateTime, $future); - } - - /** - * Detects the DateTime context - */ - protected function detectType() - { - if ($this->now->format('Y-m-d') !== $this->dateTime->format('Y-m-d')) { - $this->type = self::TYPE_DATETIME; - return; - } - - if ( - $this->now->format('Y-m-d') === $this->dateTime->format('Y-m-d') && - (abs($this->now->getTimestamp() - $this->dateTime->getTimestamp()) >= self::HOUR) - ) { - $this->type = self::TYPE_TIME; - return; - } - - if ( - $this->now->format('Y-m-d') === $this->dateTime->format('Y-m-d') && - (abs($this->now->getTimestamp() - $this->dateTime->getTimestamp()) < self::HOUR) - ) { - $this->type = self::TYPE_TIMESPAN; - return; - } - } - - /** - * Normalizes the given DateTime - * - * @param DateTime|int $dateTime - * - * @return DateTime - */ - public static function normalize($dateTime) - { - if (! ($dt = $dateTime) instanceof DateTime) { - $dt = new DateTime(); - $dt->setTimestamp($dateTime); - } - return $dt; - } - - /** - * Checks whether DateTime is a date with time - * - * @return bool - */ - public function isDateTime() - { - return $this->type === self::TYPE_DATETIME; - } - - /** - * Checks whether DateTime is a time of the current day - * - * @return bool - */ - public function isTime() - { - return $this->type === self::TYPE_TIME; - } - - /** - * Checks whether DateTime is in a defined interval - * - * @return bool - */ - public function isTimespan() - { - return $this->type === self::TYPE_TIMESPAN; - } - - /** - * Returns the type of the DateTime - * - * @return mixed - */ - public function getType() - { - return $this->type; - } - - /** - * Renders the DateTime on the basis of the type and returns suited text - * - * @param string $dateTimeText - * @param string $timeText - * @param string $timespanText - * - * @return string - */ - public function render($dateTimeText, $timeText, $timespanText) - { - if ($this->isDateTime()) { - return sprintf($dateTimeText, $this); - } elseif ($this->isTime()) { - return sprintf($timeText, $this); - } elseif ($this->isTimespan()) { - return sprintf($timespanText, $this); - } - - return $dateTimeText; - } - - /** - * Returns a rendered html wrapped text - * - * @return string - */ - public function __toString() - { - switch ($this->type) { - case self::TYPE_DATETIME: - $format = $this->dateTime->format('d.m.Y - H:i:s'); - break; - case self::TYPE_TIME: - $format = $this->dateTime->format('H:i:s'); - break; - case self::TYPE_TIMESPAN: - $format = $this->dateTime->diff($this->now)->format(t('%im %ss', 'timespan')); - break; - default: - $format = $this->dateTime->format('d.m.Y - H:i:s'); - break; - } - - $css = ''; - if ($this->type === self::TYPE_TIMESPAN) { - $css = $this->future === true ? 'timeuntil' : 'timesince'; - } - - return sprintf( - '%s', - $css, - $this->dateTime->format('d.m.Y - H:i:s'), - $format - ); - } -}