Пример #1
0
 public function testValidateDateString()
 {
     $d = Validation::validateDateString('2016-03-15');
     $this->assertEquals('2016-03-15', $d->format('Y-m-d'), "Y-m-d format");
     $d = Validation::validateDateString('3/15/2016');
     $this->assertEquals('2016-03-15', $d->format('Y-m-d'), "n/j/Y format");
     $d = Validation::validateDateString('03/15/2016');
     $this->assertEquals('2016-03-15', $d->format('Y-m-d'), "m/d/Y format");
     $d = Validation::validateDateString('3/2/2016');
     $this->assertEquals('2016-03-02', $d->format('Y-m-d'), "n/j/Y format");
     $d = Validation::validateDateString('02/08/1987');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "m/d/Y format");
     $d = Validation::validateDateString('2/8/87');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "n/j/y format");
     $d = Validation::validateDateString('02/08/87');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "m/d/y format");
     $d = Validation::validateDateString('February 08, 1987');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "F d, Y format");
     $d = Validation::validateDateString('February 8, 1987');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "F j, Y format");
     try {
         $d = Validation::validateDateString('February 08, 87');
     } catch (\Littled\Exception\ContentValidationException $ex) {
         $this->assertEquals("Unrecognized date value.", $ex->getMessage(), "F d, y format");
     }
 }
Пример #2
0
 public function collectValue($read_cookies = true)
 {
     parent::collectValue($read_cookies);
     if ($this->value) {
         try {
             $d = Validation::validateDateString($this->value);
             $this->value = $d->format("m/d/Y");
         } catch (ContentValidationException $ex) {
             $this->value = "[" . $ex->getMessage() . "]";
         }
     }
 }