Skip to content

Commit

Permalink
Correctly marshall 12:00 times with meridans.
Browse files Browse the repository at this point in the history
Refs #7430
  • Loading branch information
markstory committed Sep 30, 2015
1 parent 543b49b commit 47bfec7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/Database/Type/DateTimeType.php
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Validation/Validation.php
Expand Up @@ -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];
Expand Down
8 changes: 8 additions & 0 deletions tests/TestCase/Database/Type/DateTimeTypeTest.php
Expand Up @@ -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,
Expand Down

0 comments on commit 47bfec7

Please sign in to comment.