Commit 81372b25 authored by Karamel's avatar Karamel
Browse files

Allow to pass timestamp as a string to DateUtils::readDate.

parent 76f4e9b8
......@@ -95,8 +95,12 @@ class DateUtils
*/
public static function readDate($input) {
if ($input === null) { return null; }
if (is_int($input)) {
return static::readTimestamp($input);
if (is_numeric($input)) {
if (is_int($input)) {
return static::readTimestamp($input);
} else {
return static::readTimestamp(intval($input));
}
}
if ($input instanceof \DateTime) {
return $input;
......
......@@ -74,6 +74,13 @@ class DateUtilsTest extends TestCase {
$this->assertEquals($timestamp, $date->getTimestamp());
}
public function testReadDateTimestampString() {
$timestamp = '1171502725';
$date = DateUtils::readDate($timestamp);
$this->assertNotEquals(false, $date);
$this->assertEquals($timestamp, $date->getTimestamp());
}
public function testReadDateDateTime() {
$timestamp = 1171502725;
$date = new \DateTime();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment