public function testMergeDateIntoTime() { $date = new DateTime(); $date->setDate(2016, 1, 2); $time = new DateTime(); $time->setDate(2014, 3, 1); $time = Dates::mergeDateIntoTime($date, $time); $format = 'Y-m-d'; $this->assertEquals($date->format($format), $time->format($format)); }
/** * Constructs a new IO with a config array * * @param string $name The name of the IO * @param string $date The date of the IO in standard date format * @param string $timeStart The start time of the IO in standard time format * @param string $timeEnd The end time of the IO in standard time format * @param bool $dummy Whether the IO is a dummy. default: false * * @throws InvalidArgumentException On validation error */ public function __construct($name, $date, $timeStart, $timeEnd, $dummy = false) { if (!preg_match(Dates::STD_TIME_FORMAT_REGEX, $timeStart)) { throw new InvalidArgumentException("\$timeStart is not in valid time format"); } if (!preg_match(Dates::STD_TIME_FORMAT_REGEX, $timeEnd)) { throw new InvalidArgumentException("\$timeEnd is not in valid time format"); } if (!preg_match(Dates::STD_DATE_FORMAT_REGEX, $date)) { throw new InvalidArgumentException("\$date is not in valid date format"); } if (!$dummy and empty($name)) { throw new InvalidArgumentException("\$name must not be empty when Irregular Opening is not a dummy"); } $date = new DateTime($date); $this->name = $name; $this->timeStart = Dates::mergeDateIntoTime($date, new DateTime($timeStart)); $this->timeEnd = Dates::mergeDateIntoTime($date, new DateTime($timeEnd)); $this->dummy = $dummy; if (Dates::compareTime($this->timeStart, $this->timeEnd) >= 0) { $this->timeEnd->add(new DateInterval('P1D')); } }