Skip to content

Commit

Permalink
Merge pull request #10 from magicoli/master
Browse files Browse the repository at this point in the history
Fix #9 Unix timestamp string not detected
  • Loading branch information
flack committed Sep 8, 2022
2 parents 3e61e8b + 9cc0885 commit 3333620
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Ranger.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ private function prepare_date($input)
if ($input instanceof DateTime) {
return $input;
}
if (is_string($input)) {
return new Datetime($input);
}
if (is_int($input)) {
if (is_numeric($input)) {
$date = new Datetime;
$date->setTimestamp($input);
$date->setTimestamp(intval($input));
return $date;
}
if (is_string($input)) {
return new Datetime($input);
}
if ($input === null) {
return new Datetime;
}
Expand Down
9 changes: 9 additions & 0 deletions test/RangerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,13 @@ public function testIssue8()
$result = $r->format('2022-05-04 20:00:00', '2022-05-04 20:00:00');
$this->assertEquals('04.05.2022, 20:00', $result);
}

public function testIssue9()
{
$r = new Ranger('en');
$this->assertEquals('Sep 5–12, 2022', $r->format(1662336000, 1662940800));
$this->assertEquals('Sep 5–12, 2022', $r->format(1662336000.5, 1662940800.5));
$this->assertEquals('Sep 5–12, 2022', $r->format("1662336000", "1662940800"));
$this->assertEquals('Sep 5–12, 2022', $r->format("1662336000.5", "1662940800.5"));
}
}

0 comments on commit 3333620

Please sign in to comment.