Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/DifferenceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public function diffForHumans(
$unit = 'second';
break;
}

if ($count === 0 && $unit === 'second') {
return $this->translate->singular('just_now');
}

$time = $this->translate->plural($unit, $count, ['count' => $count]);
if ($absolute) {
return $time;
Expand Down
1 change: 1 addition & 0 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Translator
'minute_plural' => '{count} minutes',
'second' => '1 second',
'second_plural' => '{count} seconds',
'just_now' => 'just now',
'ago' => '{time} ago',
'from_now' => '{time} from now',
'after' => '{time} after',
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Date/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,14 @@ public function testDiffForHumansWithNowAbsolute()
public function testDiffForHumansWithoutDiff()
{
$this->wrapWithTestNow(function () {
$this->assertSame('0 seconds ago', ChronosDate::parse(Chronos::now())->diffForHumans());
$this->assertSame('just now', ChronosDate::parse(Chronos::now())->diffForHumans());
});
}

public function testDiffForHumansWithoutDiffAbsolute()
{
$this->wrapWithTestNow(function () {
$this->assertSame('0 seconds', ChronosDate::parse(Chronos::now())->diffForHumans(null, true));
$this->assertSame('just now', ChronosDate::parse(Chronos::now())->diffForHumans(null, true));
});
}
}
4 changes: 2 additions & 2 deletions tests/TestCase/DateTime/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,14 @@ public function testDiffForHumansWithNowAbsolute()
public function testDiffForHumansWithoutDiff()
{
$this->wrapWithTestNow(function () {
$this->assertSame('0 seconds ago', Chronos::now()->diffForHumans());
$this->assertSame('just now', Chronos::now()->diffForHumans());
});
}

public function testDiffForHumansWithoutDiffAbsolute()
{
$this->wrapWithTestNow(function () {
$this->assertSame('0 seconds', Chronos::now()->diffForHumans(null, true));
$this->assertSame('just now', Chronos::now()->diffForHumans(null, true));
});
}

Expand Down