spatie / period

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

Add periods to a PeriodCollection? #112

Closed VConsulting closed 1 year ago

VConsulting commented 1 year ago

Hello,

Probably stupid, but I can't. How to fill the PeriodCollection via an array of data:

                $collection = new PeriodCollection();
                foreach ($this->array_events as $event) {
                    $collection->Period::make($event['event_start'], $event['event_ended'], Precision::MINUTE());
                }
                $gaps = $collection->gaps();

It doesn't work, error: Undefined property: Spatie\Period\PeriodCollection::$Period

thank you

VConsulting commented 1 year ago

I found the solution through the video https://www.youtube.com/watch?v=k97mwdmocZY

                $collection = new PeriodCollection();
                foreach ($this->array_events[$day] as $event) {
                    $collection = $collection->add(Period::make($event['event_start'], $event['event_ended'], Precision::MINUTE()));
                }
                $gaps = $collection->gaps();