From 4cd3f904591b7839248153c688c29ab37d817f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rn=20=C3=85ne?= Date: Fri, 26 Aug 2016 22:16:54 +0200 Subject: [PATCH] Add getRelativeDate() in Event. --- src/pvv/side/event.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/pvv/side/event.php b/src/pvv/side/event.php index 76eab76..4f56828 100644 --- a/src/pvv/side/event.php +++ b/src/pvv/side/event.php @@ -15,6 +15,25 @@ abstract class Event { return $this->start; } + public function getRelativeDate() { + if (Agenda::isToday($this->getStart())) { + return 'i dag'; + } + if (Agenda::isTomorrow($this->getStart())) { + return 'i morgen'; + } + if (Agenda::isThisWeek($this->getStart()) || $this->getStart()->sub(new DateInterval('P4D'))->getTimestamp() < time()) { + return strftime('%A', $this->getStart()->getTimestamp()); + } + if (Agenda::isNextWeek($this->getStart())) { + return 'neste uke'; + } + if (Agenda::isThisMonth($this->getStart())) { + return 'denne måneden'; + } + return strftime('%e. %b', $this->getStart()->getTimestamp()); + } + public abstract function getStop(); /* : DateTimeImmutable */ public abstract function getURL(); /* : string */