From b5f589c323f415bb42ea7069cb4d1a8a2233dd69 Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 31 Aug 2022 22:03:07 +0200 Subject: Update I guess - Stuffie --- includes/ical/src/EventsList.php | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 includes/ical/src/EventsList.php (limited to 'includes/ical/src/EventsList.php') diff --git a/includes/ical/src/EventsList.php b/includes/ical/src/EventsList.php new file mode 100644 index 0000000..3325368 --- /dev/null +++ b/includes/ical/src/EventsList.php @@ -0,0 +1,54 @@ + + */ +class EventsList extends \ArrayObject { + + /** + * Return array of Events + * + * @return array + */ + public function getArrayCopy(): array { + return array_values(parent::getArrayCopy()); + } + + /** + * Return sorted EventList (the newest dates are first) + * + * @return $this + */ + public function sorted(): EventsList { + $this->uasort(static function ($a, $b): int { + if ($a['DTSTART'] === $b['DTSTART']) { + return 0; + } + return ($a['DTSTART'] < $b['DTSTART']) ? -1 : 1; + }); + + return $this; + } + + /** + * Return reversed sorted EventList (the oldest dates are first) + * + * @return $this + */ + public function reversed(): EventsList { + $this->uasort(static function ($a, $b): int { + if ($a['DTSTART'] === $b['DTSTART']) { + return 0; + } + return ($a['DTSTART'] > $b['DTSTART']) ? -1 : 1; + }); + + return $this; + } + +} \ No newline at end of file -- cgit