public function testIsValid()
 {
     $this->assertFalse($this->txtTime->isValid());
     $_POST['time'] = 'Boobies';
     $this->assertFalse($this->txtTime->isValid());
     $_POST['time'] = '13:37';
     $this->assertTrue($this->txtTime->isValid());
     $_POST['time'] = '25:60';
     $this->assertFalse($this->txtTime->isValid());
     $_POST['time'] = 'pipi00:01asshole';
     $this->assertFalse($this->txtTime->isValid());
     $_POST['time'] = '1k:2b';
     $this->assertFalse($this->txtTime->isValid());
     $_POST['name'] = array('foo', 'bar');
     $this->assertFalse($this->txtTime->isValid());
 }
Beispiel #2
0
 /**
  * Get the UTC timestamp for a date/time object combination.
  *
  * @param \SpoonFormDate $date An instance of \SpoonFormDate.
  * @param \SpoonFormTime $time An instance of \SpoonFormTime.
  * @return int
  * @throws \Exception If provided $date, $time or both are invalid
  */
 public static function getUTCTimestamp(\SpoonFormDate $date, \SpoonFormTime $time = null)
 {
     // validate date/time object
     if (!$date->isValid() || $time !== null && !$time->isValid()) {
         throw new \Exception('You need to provide two objects that actually contain valid data.');
     }
     // init vars
     $year = gmdate('Y', $date->getTimestamp());
     $month = gmdate('m', $date->getTimestamp());
     $day = gmdate('j', $date->getTimestamp());
     if ($time !== null) {
         // define hour & minute
         list($hour, $minute) = explode(':', $time->getValue());
     } else {
         // user default time
         $hour = 0;
         $minute = 0;
     }
     // make and return timestamp
     return mktime($hour, $minute, 0, $month, $day, $year);
 }