Hi, I am unable to use addOpenHours() when setting the opening hours on a carbon date instance. It works if I set it using Carbon::setOpeningHours.
I was able to verify that the opening hours were correctly set on my carbon date instance by calling getOpeningHours(). However, calling addOpenHours() immediately threw InvalidArgumentException('Opening hours have not been set.')
I need to set the opening hours on the carbon date instance because opening hours can change at runtime.
Minimal reproduction
Load the mixin
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Cmixin\BusinessTime;
use Carbon\Carbon;
class AppServiceProvider extends ServiceProvider
{
/**
Register any application services.
@return void
*/
public function register()
{
//
}
/**
Bootstrap any application services.
@return void
*/
public function boot()
{
BusinessTime::enable(Carbon::class);
}
}
2. Parse a date with carbon and then set the opening hours
```php
$c = Carbon::parse($this->openingDate);
$c->setOpeningHours([
'monday' => ['09:00-12:00', '13:00-18:00'],
'tuesday' => ['09:00-12:00', '13:00-18:00'],
'wednesday' => ['09:00-12:00'],
'thursday' => ['09:00-12:00', '13:00-18:00'],
'friday' => ['09:00-12:00', '13:00-20:00'],
'saturday' => ['09:00-12:00', '13:00-16:00'],
]);
Call addOpenHours() on the carbon date instance
$c->addOpenHours(10);
At this point, InvalidArgumentException is thrown.
If I call $c->getOpeningHours() instead, I get the following:
Hi, I am unable to use
addOpenHours()
when setting the opening hours on a carbon date instance. It works if I set it usingCarbon::setOpeningHours
.I was able to verify that the opening hours were correctly set on my carbon date instance by calling
getOpeningHours()
. However, callingaddOpenHours()
immediately threwInvalidArgumentException('Opening hours have not been set.')
I need to set the opening hours on the carbon date instance because opening hours can change at runtime.
Minimal reproduction
namespace App\Providers;
use Illuminate\Support\ServiceProvider; use Cmixin\BusinessTime; use Carbon\Carbon;
class AppServiceProvider extends ServiceProvider { /**
@return void */ public function register() { // }
/**
addOpenHours()
on the carbon date instance$c->addOpenHours(10);
At this point,InvalidArgumentException
is thrown. If I call$c->getOpeningHours()
instead, I get the following: