Skip to content

Commit 3333620

Browse files
authored
Merge pull request #10 from magicoli/master
Fix #9 Unix timestamp string not detected
2 parents 3e61e8b + 9cc0885 commit 3333620

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/Ranger.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ private function prepare_date($input)
234234
if ($input instanceof DateTime) {
235235
return $input;
236236
}
237-
if (is_string($input)) {
238-
return new Datetime($input);
239-
}
240-
if (is_int($input)) {
237+
if (is_numeric($input)) {
241238
$date = new Datetime;
242-
$date->setTimestamp($input);
239+
$date->setTimestamp(intval($input));
243240
return $date;
244241
}
242+
if (is_string($input)) {
243+
return new Datetime($input);
244+
}
245245
if ($input === null) {
246246
return new Datetime;
247247
}

test/RangerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,13 @@ public function testIssue8()
245245
$result = $r->format('2022-05-04 20:00:00', '2022-05-04 20:00:00');
246246
$this->assertEquals('04.05.2022, 20:00', $result);
247247
}
248+
249+
public function testIssue9()
250+
{
251+
$r = new Ranger('en');
252+
$this->assertEquals('Sep 5–12, 2022', $r->format(1662336000, 1662940800));
253+
$this->assertEquals('Sep 5–12, 2022', $r->format(1662336000.5, 1662940800.5));
254+
$this->assertEquals('Sep 5–12, 2022', $r->format("1662336000", "1662940800"));
255+
$this->assertEquals('Sep 5–12, 2022', $r->format("1662336000.5", "1662940800.5"));
256+
}
248257
}

0 commit comments

Comments
 (0)