From b1ba2f0f51b3aa62573930d4c398f29e214b8e5a Mon Sep 17 00:00:00 2001 From: Jim Mason Date: Wed, 16 Oct 2024 19:34:53 +0100 Subject: [PATCH] finessed date and time combo generation --- ui/Home.php | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/ui/Home.php b/ui/Home.php index a5fa948b..e836d224 100644 --- a/ui/Home.php +++ b/ui/Home.php @@ -47,38 +47,29 @@ public function recentSpins() { } protected function makeDatePicker() { - $result = []; - - $now = new \DateTime(); - $result[] = clone $now; - - for($i=0; $i<6; $i++) { - $now->modify("-1 days"); - $result[] = clone $now; - } + $result = array_map(function($i) { + return (new \DateTime())->modify("-$i days"); + }, range(0, 6)); $this->addVar("dates", $result); } protected function makeTimePicker($date=null) { - $result = []; - $now = new \DateTime(); if(!$date || $now->format("Y-m-d") == $date) { // today $hour = (int)$now->format("H"); - $result[] = -1; - } else { - $hour = 23; - $result[] = $hour; - } + $initial = -1; + } else + $initial = $hour = 23; + + $result = array_filter(range(1, $hour), function($i) { + return $i % 3 === 0; + }); - do { - if($hour % 3) continue; - $result[] = $hour; - } while(--$hour > 0); + $result[] = $initial; - $this->addVar("times", $result); + $this->addVar("times", array_reverse($result)); } public function getTimes() {