示例#1
0
 public function testCompareTime()
 {
     $d1 = new DateTime('2016-02-03 12:30');
     $d2 = new DateTime('2016-12-23 01:45');
     $this->assertEquals(-1, Dates::compareTime($d2, $d1));
     $this->assertEquals(0, Dates::compareTime($d1, $d1));
     $this->assertEquals(1, Dates::compareTime($d1, $d2));
 }
示例#2
0
 /**
  * Constructs a new Period with a config array
  *
  * @param     int       $weekday    Weekday represented by integer. Monday: 0 - Sunday: 7
  * @param     string    $timeStart  The start time in standard time format
  * @param     string    $timeEnd    The end time in standard time format
  * @param     bool      $dummy      Whether this period is a dummy. default: false
  *
  * @throws    InvalidArgumentException  On validation error
  */
 public function __construct($weekday, $timeStart, $timeEnd, $dummy = false)
 {
     if (!is_int($weekday) or $weekday < 0 or $weekday > 6) {
         throw new InvalidArgumentException(sprintf('$weekday must be an integer between 0 and 6. got %s', (string) $weekday));
     }
     if (!Dates::isValidTime($timeStart)) {
         throw new InvalidArgumentException(sprintf('$timeStart must be in standard time format %s. got %s', Dates::STD_TIME_FORMAT, $timeStart));
     }
     if (!Dates::isValidTime($timeEnd)) {
         throw new InvalidArgumentException(sprintf('$timeEnd must be in standard time format %s. got %s', Dates::STD_TIME_FORMAT, $timeEnd));
     }
     $this->weekday = $weekday;
     $this->timeStart = Dates::applyWeekContext(new DateTime($timeStart, Dates::getTimezone()), $weekday);
     $this->timeEnd = Dates::applyWeekContext(new DateTime($timeEnd, Dates::getTimezone()), $weekday);
     $this->dummy = $dummy;
     $this->spansTwoDays = Dates::compareTime($this->timeStart, $this->timeEnd) >= 0;
     if ($this->spansTwoDays) {
         $this->timeEnd->add(new DateInterval('P1D'));
     }
 }
 /**
  * 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'));
     }
 }