Skip to content

Commit

Permalink
finessed date and time combo generation
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed Oct 17, 2024
1 parent 1871ac3 commit b1ba2f0
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions ui/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b1ba2f0

Please sign in to comment.