Skip to content

Commit

Permalink
Adding locale aware parsing to the TimeType class
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 18, 2015
1 parent 903bd21 commit 02906c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Database/Type/TimeType.php
Expand Up @@ -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);
}
}
15 changes: 15 additions & 0 deletions tests/TestCase/Database/Type/TimeTypeTest.php
Expand Up @@ -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'));
}
}

0 comments on commit 02906c9

Please sign in to comment.