kylekatarnls / business-time

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

isOpenOn('Y-m-d') holiday filter issue #34

Closed joecampo closed 4 years ago

joecampo commented 4 years ago

Hey there,

First off - thank you so much for package, it really is awesome!

Issue

When attempting to check if a date is open on a string formatted date e.g.

Carbon::isOpenOn('2020-07-04');

and holidaysAreClosed is set to true it produces the following error:

PHP Error:  Call to undefined method DateTime::isHoliday() in /vendor/cmixin/business-time/src/BusinessTime/DefinitionParser.php on line 194

Example

Here is an example in the live editor

Trying to solve

After taking a look at the DefinitionParser@194 expect the date object passed into the closure to be a Carbon instance, but after source diving the new implementation in spatie/opening-hours a DateTime object is what is being passed into the filters.

I was going to submit a PR, but I'm not sure the best way to go around fixing this as I don't see an easy way to parse out the holidays to check the DateTime object. Appreciate your time and help!

Using:

Laravel 7.28.1 (schedule enabled to \Illuminate\Support\Carbon) PHP 7.4.9

kylekatarnls commented 4 years ago

Good point I did not test with holidaysAreClosed