/** * Adds date-only handling to DateTime object. * Adds the ability to pass in an array with key names of variable * length but a minimum of 3 characters, upper or lower case. * Sets time to noon to avoid possible Daylight Savings transition issues. * * @param object|array|string $time -OPTIONAL * @param string $timezone -OPTIONAL * @throws InvalidArgumentException */ public function __construct($time = 'now', \DateTimeZone $timezone = null) { $timezone = null === $timezone ? new \DateTimeZone(date_default_timezone_get()) : $timezone; switch (gettype($time)) { case 'object': if (is_a($time, 'DateTime')) { parent::__construct($time->format('Y-m-d 12:00:00'), $time->getTimezone()); return; } case 'null': case 'NULL': case 'array': parent::__construct('now', $timezone); parent::setDate($time); break; case 'string': parent::__construct($time, $timezone); break; default: throw new \InvalidArgumentException('first argument is the wrong type'); } parent::setTime(12, 0, 0); }