spatie / period

Complex period comparisons
https://spatie.be/open-source
MIT License
1.55k stars 72 forks source link

Error "Undefined array key 0" fix #105

Closed aliowacom closed 2 years ago

aliowacom commented 2 years ago

There's an error, if you pass an empty PeriodCollection to overlap() or subtract() method since there's no check whether the collection actually has any values.

Steps to reproduce:


        $period = Period::make('2021-12-31', '2022-01-01');
        $collection = new PeriodCollection;

        $period->overlap(... $collection); // Throws ErrorException "Undefined array key 0"
        $period->subtract(... $collection); // Throws ErrorException "Undefined array key 0"

P.S. Thank you for your products and Merry Christmas! :)

brendt commented 2 years ago

Nice, could you also provide a test with this PR?

aliowacom commented 2 years ago

Done

brendt commented 2 years ago

Thanks!

brendt commented 2 years ago

Tagged: https://github.com/spatie/period/releases/tag/2.3.2