kylekatarnls / business-time

Carbon mixin to handle business days and opening hours
MIT License
296 stars 14 forks source link

Cannot use addOpenHours with LOCAL_MODE #31

Closed Naghal closed 4 years ago

Naghal commented 4 years ago

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

  1. Load the mixin
    
    <?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider; use Cmixin\BusinessTime; use Carbon\Carbon;

class AppServiceProvider extends ServiceProvider { /**

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'],
    ]);
  1. 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: image
kylekatarnls commented 4 years ago

Thank you. I identified the issue. I'm working on it.

kylekatarnls commented 4 years ago

This should be fixed, please try to update the cmixin/business-time 1.7.2.

Naghal commented 4 years ago

Thank you, the problem is fixed.