Skip to content

Commit 2716bcb

Browse files
committed
Fix 12PM not validating with string data.
In 252267c strict equality was used which excludes string '12'. Refs #7430
1 parent ef79994 commit 2716bcb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Validation/Validation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ protected static function _getDateString($value)
12031203

12041204
if (isset($value['hour'])) {
12051205
if (isset($value['meridian'])) {
1206-
if ($value['hour'] === 12) {
1206+
if ((int)$value['hour'] === 12) {
12071207
$value['hour'] = 0;
12081208
}
12091209
$value['hour'] = strtolower($value['meridian']) === 'am' ? $value['hour'] : $value['hour'] + 12;

tests/TestCase/Validation/ValidationTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* ValidationTest file
4-
*
53
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
64
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
75
*
@@ -1470,6 +1468,17 @@ public function testDateArray()
14701468
*/
14711469
public function testDateTimeArray()
14721470
{
1471+
$date = [
1472+
'year' => 2014,
1473+
'month' => '02',
1474+
'day' => '14',
1475+
'hour' => '12',
1476+
'minute' => '14',
1477+
'second' => '15',
1478+
'meridian' => 'pm'
1479+
];
1480+
$this->assertTrue(Validation::datetime($date));
1481+
14731482
$date = ['year' => 2014, 'month' => 2, 'day' => 14, 'hour' => 13, 'minute' => 14, 'second' => 15];
14741483
$this->assertTrue(Validation::datetime($date));
14751484

0 commit comments

Comments
 (0)