wah.moe/app/View/Components/Layout.php
2026-04-01 00:14:44 +01:00

55 lines
1.5 KiB
PHP

<?php
namespace App\View\Components;
use Closure;
use DateTime;
use DateTimeZone;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Layout extends Component {
/**
* Create a new component instance.
*/
public function __construct() {}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string {
$event = '';
if ($this->isItChristmas()) $event = 'christmas';
if ($this->isItAprilFools()) $event = 'april-fools';
if (isLegacy()) {
return view('components.layout-legacy', [
'event' => $event
]);
} else {
return view('components.layout', [
'event' => $event
]);
}
}
public function isItChristmas() : bool {
$currentDate = new DateTime();
$currentYear = intval($currentDate->format('Y'));
$startDate = new DateTime("$currentYear-11-10");
$endDate = new DateTime(($currentYear + 1) . "-01-01");
return $currentDate >= $startDate && $currentDate < $endDate;
}
public function isItAprilFools() : bool {
$tz = new DateTimeZone("Europe/London");
$currentDate = new DateTime("now", $tz);
$currentDate->setTime(0, 0);
$currentYear = intval($currentDate->format('Y'));
$aprilFools = new DateTime("$currentYear-04-01", $tz);
return $currentDate == $aprilFools;
}
}