Skip to content

Commit

Permalink
Updated to support Statamic v3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
lokmanm committed Mar 17, 2022
1 parent 4d109bf commit fc496ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@
"LuckyMedia\\BusinessHours\\ServiceProvider"
]
}
},
"require": {
"php": "^7.4 || ^8.0 || ^8.1",
"statamic/cms": "3.3.*"
}
}
26 changes: 13 additions & 13 deletions src/Tags/BusinessHoursTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public function __construct()

public function index(): array
{
$days = collect($this->defaults['hours']->value())
$days = collect($this->defaults['hours'])
->map(function ($day, $key) {
return [
'is_open' => $this->isOpen($day, $key),
'is_past' => $this->isPast($day, $key),
'enabled' => $day['enabled']->value(),
'weekday' => $day['weekday']->value(),
'start_time' => $this->formatDate($day['start_time']->value()),
'end_time' => $this->formatDate($day['end_time']->value()),
'24_hours' => $day['24_hours']->value(),
'closed' => $day['closed']->value(),
'enabled' => $day['enabled'],
'weekday' => $day['weekday'],
'start_time' => $this->formatDate($day['start_time']),
'end_time' => $this->formatDate($day['end_time']),
'24_hours' => $day['24_hours'],
'closed' => $day['closed'],
];
})
->filter(function($day) {
Expand All @@ -43,11 +43,11 @@ public function index(): array

public function exception()
{
$days = collect($this->defaults['exceptions']->value())
$days = collect($this->defaults['exceptions'])
->first(function ($day) {
$is_enabled = $day['enable_date']->value();
$start_date = Carbon::create($day['start_date']->value());
$end_date = Carbon::create($day['end_date']->value());
$is_enabled = $day['enable_date'];
$start_date = Carbon::create($day['start_date']);
$end_date = Carbon::create($day['end_date']);

if (! $is_enabled) return false;

Expand All @@ -69,7 +69,7 @@ public function exception()

public function exceptions(): array
{
return $this->defaults['exceptions']->value();
return $this->defaults['exceptions'];
}

protected function isPast($day, $key): bool
Expand Down Expand Up @@ -125,7 +125,7 @@ protected function isToday($key): bool
}

protected function formatToTime($day) {
[$hour, $minute] = explode(':', $day->value());
[$hour, $minute] = explode(':', $day);

return Carbon::createFromTime($hour, $minute);
}
Expand Down

0 comments on commit fc496ae

Please sign in to comment.