now showing night shots at appropriate times

This commit is contained in:
2026-01-09 19:06:33 -07:00
parent e003cb2fb1
commit aaca102b32
2 changed files with 26 additions and 16 deletions

View File

@@ -53,10 +53,7 @@ class WeatherController extends Controller
'detailedForecast' => $period->detailed_forecast,
]);
$background = $this->getBackgroundForForecast(
$currentPeriod?->short_forecast,
$currentPeriod?->is_daytime ?? true
);
$background = $this->getBackgroundForForecast($currentPeriod?->short_forecast);
return Inertia::render('Weather', [
'current' => $currentPeriod ? [
@@ -87,10 +84,10 @@ class WeatherController extends Controller
/**
* @return array{imageUrl: string|null, licenseHtml: string|null}
*/
private function getBackgroundForForecast(?string $forecast, bool $isDaytime): array
private function getBackgroundForForecast(?string $forecast): array
{
$folder = $this->mapForecastToFolder($forecast);
$timeOfDay = $isDaytime ? 'day' : 'night';
$timeOfDay = $this->isCurrentlyDaytime() ? 'day' : 'night';
$basePath = storage_path('app/public/backgrounds/'.$folder);
if (! File::isDirectory($basePath)) {
@@ -153,6 +150,16 @@ class WeatherController extends Controller
};
}
private function isCurrentlyDaytime(): bool
{
$sunriseHour = 6.75; // 6:45 AM
$sunsetHour = 17.5; // 5:30 PM
$currentHour = now()->hour + (now()->minute / 60);
return $currentHour >= $sunriseHour && $currentHour < $sunsetHour;
}
private function mapIconToEmoji(?string $forecast): string
{
if (! $forecast) {