diff --git a/src/DifferenceFormatter.php b/src/DifferenceFormatter.php index 3a568c7..b3a4460 100644 --- a/src/DifferenceFormatter.php +++ b/src/DifferenceFormatter.php @@ -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; diff --git a/src/Translator.php b/src/Translator.php index 37568ae..42c768c 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -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', diff --git a/tests/TestCase/Date/DiffTest.php b/tests/TestCase/Date/DiffTest.php index e78b540..3ce4b70 100644 --- a/tests/TestCase/Date/DiffTest.php +++ b/tests/TestCase/Date/DiffTest.php @@ -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)); }); } } diff --git a/tests/TestCase/DateTime/DiffTest.php b/tests/TestCase/DateTime/DiffTest.php index 90abb7e..1f58adf 100644 --- a/tests/TestCase/DateTime/DiffTest.php +++ b/tests/TestCase/DateTime/DiffTest.php @@ -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)); }); }