diff --git a/src/Carbon/CarbonInterface.php b/src/Carbon/CarbonInterface.php index 6934279ac9..65acab0719 100644 --- a/src/Carbon/CarbonInterface.php +++ b/src/Carbon/CarbonInterface.php @@ -1622,6 +1622,9 @@ public function diffFiltered(CarbonInterval $ci, Closure $callback, $date = null * ` it can be the unit name (singular or plural) or its shortcut * ` (y, m, w, d, h, min, s, ms, µs). * - 'aUnit' entry, prefer "an hour" over "1 hour" if true + * - 'altNumbers' entry, use alternative numbers if available + * (from the current language if true is passed, from the given language(s) + * if array or string is passed) * - 'join' entry determines how to join multiple parts of the string * ` - if $join is a string, it's used as a joiner glue * ` - if $join is a callable/closure, it get the list of string and should return a string diff --git a/src/Carbon/CarbonInterval.php b/src/Carbon/CarbonInterval.php index d6373e2432..e2564cd28f 100644 --- a/src/Carbon/CarbonInterval.php +++ b/src/Carbon/CarbonInterval.php @@ -1828,6 +1828,9 @@ public function getValuesSequence(): array * ` it can be the unit name (singular or plural) or its shortcut * ` (y, m, w, d, h, min, s, ms, µs). * - 'aUnit' entry, prefer "an hour" over "1 hour" if true + * - 'altNumbers' entry, use alternative numbers if available + * (from the current language if true is passed, from the given language(s) + * if array or string is passed) * - 'join' entry determines how to join multiple parts of the string * ` - if $join is a string, it's used as a joiner glue * ` - if $join is a callable/closure, it get the list of string and should return a string diff --git a/src/Carbon/Traits/Difference.php b/src/Carbon/Traits/Difference.php index 310607eb49..b7aa6622cc 100644 --- a/src/Carbon/Traits/Difference.php +++ b/src/Carbon/Traits/Difference.php @@ -489,6 +489,9 @@ public function secondsUntilEndOfDay(): float * ` it can be the unit name (singular or plural) or its shortcut * ` (y, m, w, d, h, min, s, ms, µs). * - 'aUnit' entry, prefer "an hour" over "1 hour" if true + * - 'altNumbers' entry, use alternative numbers if available + * (from the current language if true is passed, from the given language(s) + * if array or string is passed) * - 'join' entry determines how to join multiple parts of the string * ` - if $join is a string, it's used as a joiner glue * ` - if $join is a callable/closure, it get the list of string and should return a string diff --git a/tests/CarbonInterval/ConstructTest.php b/tests/CarbonInterval/ConstructTest.php index 1f03af6945..f976f13190 100644 --- a/tests/CarbonInterval/ConstructTest.php +++ b/tests/CarbonInterval/ConstructTest.php @@ -435,18 +435,34 @@ public function testFromSerialization() $past = new Carbon('-3 Days'); $today = new Carbon('today'); $interval = $today->diffAsCarbonInterval($past); + /** @var CarbonInterval $copy */ $copy = unserialize(serialize($interval)); + $this->assertInstanceOf(CarbonInterval::class, $copy); + + $this->assertSame('2 days', $interval->forHumans(parts: 1)); + $this->assertSame('2 days', $copy->forHumans(parts: 1)); + $this->assertSame(['en'], array_keys($interval->getLocalTranslator()->getMessages()) ?: ['en']); $this->assertSame(['en'], array_keys($copy->getLocalTranslator()->getMessages()) ?: ['en']); + $this->assertSame($interval->locale, $copy->locale); + + // Ignore translator for the English comparison + $copy->setLocalTranslator($interval->getLocalTranslator()); - $this->assertEquals($interval->locale('en'), $copy); + $this->assertEquals($interval, $copy); - $interval = $today->locale('zh')->diffAsCarbonInterval($past); + $interval = $today->locale('ja')->diffAsCarbonInterval($past); + /** @var CarbonInterval $copy */ $copy = unserialize(serialize($interval)); - $this->assertSame(['zh'], array_keys($interval->getLocalTranslator()->getMessages()) ?: ['en']); - $this->assertSame(['zh'], array_keys($copy->getLocalTranslator()->getMessages()) ?: ['en']); + $this->assertInstanceOf(CarbonInterval::class, $copy); + + $this->assertSame('二日', $interval->forHumans(['altNumbers' => true, 'parts' => 1])); + $this->assertSame('二日', $copy->forHumans(['altNumbers' => true, 'parts' => 1])); + + $this->assertSame(['ja'], array_keys($interval->getLocalTranslator()->getMessages())); + $this->assertSame(['ja'], array_keys($copy->getLocalTranslator()->getMessages())); $this->assertEquals($interval, $copy); }