@php /* The countdown leaves in seconds, not as a time: it does not depend on the clock of whoever is looking */ $zone = $siteData->timezone ?: 'America/Sao_Paulo'; $now = \Illuminate\Support\Carbon::now($zone); $weekdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']; $dayLabel = [ 'sun' => __('radio.weekday_short_sun'), 'mon' => __('radio.weekday_short_mon'), 'tue' => __('radio.weekday_short_tue'), 'wed' => __('radio.weekday_short_wed'), 'thu' => __('radio.weekday_short_thu'), 'fri' => __('radio.weekday_short_fri'), 'sat' => __('radio.weekday_short_sat'), ]; $playlistName = $playlists->pluck('name', 'id'); $next = null; foreach ($schedules as $schedule) { if ($schedule->status !== '1' || ! $playlistName->has($schedule->playlist_id)) { continue; } $when = null; if ($schedule->type === '2') { if (! $schedule->date) { continue; } $marked = \Illuminate\Support\Carbon::parse($schedule->date . ' ' . $schedule->time, $zone); $when = $marked->gt($now) ? $marked : null; } else { /* weekly: the first marked day from here on */ for ($ahead = 0; $ahead <= 7 && $when === null; $ahead++) { $day = $now->copy()->addDays($ahead); $column = $weekdays[(int) $day->dayOfWeek]; if ($schedule->{$column} !== '1') { continue; } $marked = $day->copy()->setTimeFromTimeString($schedule->time); if ($marked->gt($now)) { $when = $marked; } } } if ($when === null || ($next && $next['when']->lte($when))) { continue; } $next = [ 'id' => $schedule->id, 'name' => $playlistName[$schedule->playlist_id], 'when' => $when, 'day' => $dayLabel[$weekdays[(int) $when->dayOfWeek]], 'hour' => $when->format('H:i'), 'in' => max(0, (int) $now->diffInSeconds($when, false)), ]; } @endphp @if($next) {{ __('radio.home_next_sched_title') }} {{ $next['name'] }} -- {{ Str::upper($next['day']) }} {{ $next['hour'] }} @endif