123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Yr\Forecast;
- use App\Yr\Forecast\Tabular\Statistics;
- use App\Yr\Forecast\Tabular\Time;
- class Tabular implements \IteratorAggregate {
- private $time = [];
- private $stats;
- public function __construct(?\SimpleXMLElement $xml) {
- $this->stats = new Statistics();
- if ($xml != null)
- foreach ($xml->time as $time)
- $this->addTime(new Time($time));
- }
- protected function addTime(Time $time): self {
- $this->time[] = $time;
- $this->stats->analyse($time);
- return $this;
- }
- public function getStatistics(): array {
- return $this->stats;
- }
- 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 getIterator(): \Generator {
- foreach ($this->time as $time)
- yield $time;
- }
- }
|