Skip to content

Commit e619831

Browse files
author
Jimmi Westerberg
committed
Handle timediff from 1h30m as 2 hours.
There was a bug with 1h and 30mins given 1 hours back. This should be 2 hours. I added a simple check to see if the returning hour was 1, if so, i return 2. This will now give the indented number of hours. Changed the test to check, if "2 hours ago" is returned with 90mins and 110mins instead of just checking for "hours ago". Issue jimmiw#79
1 parent 5c09f10 commit e619831

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Westsworld/TimeAgo/Language.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private function getTimeDifference(DateInterval $timeDifference)
8989
// rule 5
9090
// between 1hour29mins59secs and 23hours59mins29secs
9191
if ($this->isLessThan23Hours59Mins29Seconds($timeDifference)) {
92-
return $this->translate('hours', $timeDifference->h);
92+
return $this->translate('hours', $timeDifference->h === 1 ? 2 : $timeDifference->h);
9393
}
9494

9595
// rule 6

tests/TimeagoTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function testTimeAgoInWords()
5757
$this->assertNotEquals('about 1 hour ago', $timeAgo->inWordsFromStrings("-90 minute"));
5858

5959
// testing about 2..24 hours
60-
$this->assertContains('hours ago', $timeAgo->inWordsFromStrings("-90 minute"));
60+
$this->assertEquals('2 hours ago', $timeAgo->inWordsFromStrings("-90 minute"));
61+
$this->assertEquals('2 hours ago', $timeAgo->inWordsFromStrings("-110 minute"));
6162
$this->assertContains('hours ago', $timeAgo->inWordsFromStrings("-23 hour -59 minute -29 second"));
6263
$this->assertNotContains('hours ago', $timeAgo->inWordsFromStrings("-23 hour -59 minute -30 second"));
6364
$this->assertNotContains('hours ago', $timeAgo->inWordsFromStrings("-24 hour"));

0 commit comments

Comments
 (0)