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 ...@@ -95,8 +95,12 @@ class DateUtils
*/ */
public static function readDate($input) { public static function readDate($input) {
if ($input === null) { return null; } if ($input === null) { return null; }
if (is_numeric($input)) {
if (is_int($input)) { if (is_int($input)) {
return static::readTimestamp($input); return static::readTimestamp($input);
} else {
return static::readTimestamp(intval($input));
}
} }
if ($input instanceof \DateTime) { if ($input instanceof \DateTime) {
return $input; return $input;
......
...@@ -74,6 +74,13 @@ class DateUtilsTest extends TestCase { ...@@ -74,6 +74,13 @@ class DateUtilsTest extends TestCase {
$this->assertEquals($timestamp, $date->getTimestamp()); $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() { public function testReadDateDateTime() {
$timestamp = 1171502725; $timestamp = 1171502725;
$date = new \DateTime(); $date = new \DateTime();
......
Supports Markdown
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