spatie / period

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

PeriodCollection with null element after diff #23

Closed alnidok closed 5 years ago

alnidok commented 5 years ago

Hi, if I calculate diff between two not intersected periods and try to loop: Return value of Spatie\Period\PeriodCollection::current() must be an instance of Spatie\Period\Period, null returned

$dayPeriod = Period::make('2019-02-01 15:00:00', '2019-02-01 20:00:00', Precision::MINUTE);
$events = new PeriodCollection(
    // $dayPeriod does not contain this event
    Period::make('2019-02-01 10:00:00', '2019-02-01 14:00:00', Precision::MINUTE)
);
$periods = $dayPeriod->diff(...$events);

foreach ($periods as $period) { //throw TypeError
    var_dump($period);
}
brendt commented 5 years ago

Thanks for reporting this bug! It's fixed in 1.1.1: https://github.com/spatie/period/releases/tag/1.1.1