Esempio n. 1
0
 /** Action: Render Single Period */
 public static function renderSinglePeriod()
 {
     $weekday = $_POST['weekday'];
     $timeStart = $_POST['timeStart'];
     $timeEnd = $_POST['timeEnd'];
     $config = array('weekday' => $weekday);
     $config['timeStart'] = Dates::isValidTime($timeStart) ? $timeStart : '00:00';
     $config['timeEnd'] = Dates::isValidTime($timeEnd) ? $timeEnd : '00:00';
     $period = new Period($config['weekday'], $config['timeStart'], $config['timeEnd']);
     echo self::renderTemplate('ajax/op-set-period.php', array('period' => $period), 'always');
     die;
 }
Esempio n. 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'));
     }
 }
Esempio n. 3
0
 public function testIsValidTime()
 {
     $this->assertTrue(Dates::isValidTime('01:30'));
     $this->assertFalse(Dates::isValidTime('01:348'));
 }