Skip to content

Commit

Permalink
fix DatePeriod use on old php
Browse files Browse the repository at this point in the history
  • Loading branch information
smhg committed Jun 26, 2023
1 parent 4c65c15 commit b5b7792
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Timespan/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Timespan;

use \DatePeriod;
use \IteratorAggregate;

class Collection extends \ArrayObject
{
Expand All @@ -12,11 +13,18 @@ class Collection extends \ArrayObject
public function __construct($mixed = null)
{
if ($mixed instanceof DatePeriod) {
$iterator = $mixed;

if ($iterator instanceof IteratorAggregate) {
$iterator = $mixed->getIterator();
}

$previousDate = null;
foreach ($mixed->getIterator() as $date) {
foreach ($iterator as $date) {
if ($previousDate) {
$this[] = new Timespan($previousDate, $date);
}

$previousDate = $date;
}
} elseif (is_array($mixed)) {
Expand Down

0 comments on commit b5b7792

Please sign in to comment.