Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix 12PM not validating with string data.
In 252267c strict equality was used which excludes string '12'.

Refs #7430
  • Loading branch information
markstory committed Sep 29, 2015
1 parent ef79994 commit 2716bcb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Validation/Validation.php
Expand Up @@ -1203,7 +1203,7 @@ protected static function _getDateString($value)

if (isset($value['hour'])) {
if (isset($value['meridian'])) {
if ($value['hour'] === 12) {
if ((int)$value['hour'] === 12) {
$value['hour'] = 0;
}
$value['hour'] = strtolower($value['meridian']) === 'am' ? $value['hour'] : $value['hour'] + 12;
Expand Down
13 changes: 11 additions & 2 deletions tests/TestCase/Validation/ValidationTest.php
@@ -1,7 +1,5 @@
<?php
/**
* ValidationTest file
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -1470,6 +1468,17 @@ public function testDateArray()
*/
public function testDateTimeArray()
{
$date = [
'year' => 2014,
'month' => '02',
'day' => '14',
'hour' => '12',
'minute' => '14',
'second' => '15',
'meridian' => 'pm'
];
$this->assertTrue(Validation::datetime($date));

$date = ['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15];
$this->assertTrue(Validation::datetime($date));

Expand Down

0 comments on commit 2716bcb

Please sign in to comment.