From 47bfec70930a95b62a54ec3e496dffb7230c578f Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 29 Sep 2015 22:11:40 -0400 Subject: [PATCH] Correctly marshall 12:00 times with meridans. Refs #7430 --- src/Database/Type/DateTimeType.php | 3 +++ src/Validation/Validation.php | 6 +++--- tests/TestCase/Database/Type/DateTimeTypeTest.php | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Database/Type/DateTimeType.php b/src/Database/Type/DateTimeType.php index d15971ea2bc..2eb8b155788 100644 --- a/src/Database/Type/DateTimeType.php +++ b/src/Database/Type/DateTimeType.php @@ -165,6 +165,9 @@ public function marshal($value) $format .= sprintf('%d-%02d-%02d', $value['year'], $value['month'], $value['day']); } + if (isset($value['meridian']) && (int)$value['hour'] === 12) { + $value['hour'] = 0; + } if (isset($value['meridian'])) { $value['hour'] = strtolower($value['meridian']) === 'am' ? $value['hour'] : $value['hour'] + 12; } diff --git a/src/Validation/Validation.php b/src/Validation/Validation.php index bb4c812d8b5..b450d0f61cb 100644 --- a/src/Validation/Validation.php +++ b/src/Validation/Validation.php @@ -1202,10 +1202,10 @@ protected static function _getDateString($value) } if (isset($value['hour'])) { + if (isset($value['meridian']) && (int)$value['hour'] === 12) { + $value['hour'] = 0; + } if (isset($value['meridian'])) { - if ((int)$value['hour'] === 12) { - $value['hour'] = 0; - } $value['hour'] = strtolower($value['meridian']) === 'am' ? $value['hour'] : $value['hour'] + 12; } $value += ['minute' => 0, 'second' => 0]; diff --git a/tests/TestCase/Database/Type/DateTimeTypeTest.php b/tests/TestCase/Database/Type/DateTimeTypeTest.php index dd08c0147d5..ab676bae45a 100644 --- a/tests/TestCase/Database/Type/DateTimeTypeTest.php +++ b/tests/TestCase/Database/Type/DateTimeTypeTest.php @@ -152,6 +152,14 @@ public function marshalProvider() ], new Time('2014-02-14 01:14:15') ], + [ + [ + 'year' => 2014, 'month' => 2, 'day' => 14, + 'hour' => 12, 'minute' => 04, 'second' => 15, + 'meridian' => 'pm' + ], + new Time('2014-02-14 12:04:15') + ], [ [ 'year' => 2014, 'month' => 2, 'day' => 14,