Skip to content
Permalink
Browse files

Fixed datetime validation to accept correctly meridian

  • Loading branch information...
lorenzo committed Jul 2, 2015
1 parent 4019f6f commit 7eb26ff320c26db132ab1846e3cb070f1a8572f3
Showing with 20 additions and 3 deletions.
  1. +2 −2 src/Validation/Validation.php
  2. +18 −1 tests/TestCase/Validation/ValidationTest.php
@@ -415,8 +415,8 @@ public static function datetime($check, $dateFormat = 'ymd', $regex = null)
}
$parts = explode(' ', $check);
if (!empty($parts) && count($parts) > 1) {
$time = array_pop($parts);
$date = implode(' ', $parts);
$date = array_shift($parts);
$time = implode(' ', $parts);
$valid = static::date($date, $dateFormat, $regex) && static::time($time);
}
return $valid;
@@ -1534,6 +1534,23 @@ public function testTimeArray()
$this->assertFalse(Validation::time($date));
}
/**
* Tests that it is possible to pass a median (AM, PM) to the dateTime validation
*
* @return void
*/
public function testDateTimeWithMeriadian()
{
$this->assertTrue(Validation::dateTime('10/04/2007 1:50 AM', ['dmy']));
$this->assertTrue(Validation::dateTime('12/04/2017 1:38 PM', ['dmy']));
$this->assertTrue(Validation::dateTime('10/04/2007 1:50 am', ['dmy']));
$this->assertTrue(Validation::dateTime('12/04/2017 1:38 pm', ['dmy']));
$this->assertTrue(Validation::dateTime('12/04/2017 1:38pm', ['dmy']));
$this->assertTrue(Validation::dateTime('12/04/2017 1:38AM', ['dmy']));
$this->assertFalse(Validation::dateTime('12/04/2017 58:38AM', ['dmy']));
}
/**
* testBoolean method
*
@@ -2239,7 +2256,7 @@ public function testDatetime()
$this->assertTrue(Validation::datetime('27/12/2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('27/12/2006 9:00', 'dmy'));
$this->assertTrue(Validation::datetime('27 12 2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('27 12 2006 1:00pm', 'dmy'));
$this->assertFalse(Validation::datetime('27 12 2006 24:00', 'dmy'));
$this->assertFalse(Validation::datetime('00-00-0000 1:00pm', 'dmy'));

0 comments on commit 7eb26ff

Please sign in to comment.
You can’t perform that action at this time.