stats = new Statistics(); if ($xml != null) foreach ($xml->time as $time) $this->addTime(new Time($time)); } /** * Add a Time-object to the tabular * * @return Tabular */ protected function addTime(Time $time): self { $this->time[] = $time; $this->stats->analyse($time); return $this; } /** * Get statistics for the Time-object collection * * @return Statistics */ public function getStatistics(): Statistics { return $this->stats; } /** * Remove superfluous weather data. * * Checks if the data in the Time-object differs from * the current Time-object and returns the unique data * * @return Variations */ public function getVariations(): Variations { return new Variations($this->time); } /** * Filter data between a certain periode, e.g * ``` * $forcast->between( * $forcast->getSunset(), * $forecast->getSunrise()->add( * new \DateInterval('P1D') * ) * ); * ``` * to only show from sunset today unti sunrise tomorrow * * @return Tabular with new collection */ public function getBetween(\DateTimeInterface $from, \DateTimeInterface $until): self { $n = new Tabular(null); foreach ($this as $time) if ($time->getFrom() >= $from && $time->getUntil() <= $until) $n->addTime($time); return $n; } public function getFrom(): \DateTimeInterface { return current($this->time)->getFrom(); } public function getUntil(): \DateTimeInterface { return current(array_reverse($this->time))->getUntil(); } /** * {@inheritDoc} */ public function getIterator(): \Generator { foreach ($this->time as $time) yield $time; } }