public function __construct(\DateTime $startDate, \DateTime $endDate)
{
$endDate = clone $endDate;
$endDate->modify('+1 day');
if ($startDate >= $endDate) {
throw new \LogicException('Start date must be earlier than end date.');
}
// Hack to make it work on HHVM.
$period = new \DatePeriod($startDate, new \DateInterval('P1D'), $endDate);
/** @var \DateTime $date */
foreach ($period as $date) {
$format = 'Y-m-d H:i:s';
$this->datePeriod[] = \DateTime::createFromFormat($format, $date->format($format), $date->getTimezone());
}
}