Skip to content

Commit

Permalink
DTCE-2118: Fix availability when closing time is past midnight UTC (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonning authored Aug 2, 2024
1 parent 71af63d commit 335f5a5
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions resources/views/components/widget.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,36 @@

@if($settings->enabled)
@php
$currentTime = Carbon::now('UTC')->format('H:i:s');
$currentTime = Carbon::now('UTC');
// Chat
$chatToday = OpeningHours::chat()->today()->first();
$chatOpeningTime = $currentTime->copy()->setTimeFrom($chatToday->opening_time_in_utc);
$chatClosingTime = $currentTime->copy()->setTimeFrom($chatToday->closing_time_in_utc);
if ($chatClosingTime->lessThan($chatOpeningTime)) {
$chatClosingTime->addDay();
}
$chatIsAvailable = $settings->chat_enabled
&& $chatToday->enabled
&& ($currentTime >= $chatToday->opening_time_in_utc)
&& ($currentTime <= $chatToday->closing_time_in_utc);
&& $currentTime->greaterThanOrEqualTo($chatOpeningTime)
&& $currentTime->lessThan($chatClosingTime);
// Call
$callToday = OpeningHours::call()->today()->first();
$callOpeningTime = $currentTime->copy()->setTimeFrom($callToday->opening_time_in_utc);
$callClosingTime = $currentTime->copy()->setTimeFrom($callToday->closing_time_in_utc);
if ($callClosingTime->lessThan($callOpeningTime)) {
$callClosingTime->addDay();
}
$callIsAvailable = $settings->call_enabled
&& $callToday->enabled
&& ($currentTime >= $callToday->opening_time_in_utc)
&& ($currentTime <= $callToday->closing_time_in_utc);
&& $currentTime->greaterThanOrEqualTo($callOpeningTime)
&& $currentTime->lessThan($callClosingTime);
@endphp

<x-lego::app-asset
Expand Down

0 comments on commit 335f5a5

Please sign in to comment.