diff --git a/src/Database/Type/TimeType.php b/src/Database/Type/TimeType.php index f0387440a91..e47c54f665b 100644 --- a/src/Database/Type/TimeType.php +++ b/src/Database/Type/TimeType.php @@ -28,4 +28,13 @@ class TimeType extends \Cake\Database\Type\DateTimeType * @var string */ protected $_format = 'H:i:s'; + + /** + * {@inheritDoc} + */ + protected function _parseValue($value) + { + $class = static::$dateTimeClass; + return $class::parseTime($value, $this->_localeFormat); + } } diff --git a/tests/TestCase/Database/Type/TimeTypeTest.php b/tests/TestCase/Database/Type/TimeTypeTest.php index 25cf66c908b..afa949f72d0 100644 --- a/tests/TestCase/Database/Type/TimeTypeTest.php +++ b/tests/TestCase/Database/Type/TimeTypeTest.php @@ -167,4 +167,19 @@ public function testMarshal($value, $expected) $this->assertSame($expected, $result); } } + + /** + * Tests marshalling dates using the locale aware parser + * + * @return void + */ + public function testMarshalWithLocaleParsing() + { + $this->type->useLocaleParser(); + $expected = new Time('23:23:00'); + $result = $this->type->marshal('11:23pm'); + $this->assertEquals($expected->format('H:i'), $result->format('H:i')); + + $this->assertNull($this->type->marshal('derp:23')); + } }