Skip to content

Commit

Permalink
Merge pull request #2822 from briannesbitt/fix/issue-2820-locale-in-s…
Browse files Browse the repository at this point in the history
…ettings

Exclude locale from getSetting() if set by default
  • Loading branch information
kylekatarnls authored Jul 11, 2023
2 parents 075ee12 + 6a69c97 commit 7ce9ddc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Carbon/Traits/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public function getSettings()
foreach ($map as $property => $key) {
$value = $this->$property ?? null;

if ($value !== null) {
if ($value !== null && ($key !== 'locale' || $value !== 'en' || $this->localTranslator)) {
$settings[$key] = $value;
}
}
Expand All @@ -437,7 +437,7 @@ public function getSettings()
*/
public function __debugInfo()
{
$infos = array_filter(get_object_vars($this), function ($var) {
$infos = array_filter(get_object_vars($this), static function ($var) {
return $var;
});

Expand Down
4 changes: 4 additions & 0 deletions tests/Carbon/MacroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,12 @@ public function testMutabilityOfMixinMethodReturnedValue()

$now = Carbon::now();

$this->assertSame('Monday', $now->copy()->startOfWeek()->dayName);

$copy = $now->copyWithAppTz(false, 'Europe/Paris');

$this->assertSame('Monday', $copy->copy()->startOfWeek()->dayName);

$this->assertSame('Europe/Paris', $copy->format('e'));
$this->assertSame('UTC', $now->format('e'));

Expand Down
11 changes: 3 additions & 8 deletions tests/Jenssegers/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Tests\Jenssegers;

use Carbon\Carbon;
use DateTimeImmutable;

class DateTest extends TestCaseBase
{
Expand All @@ -24,19 +25,13 @@ public function testConstructFromString()
$date = new Carbon('2013-01-31');
$this->assertSame(1359590400, $date->getTimestamp());

$before = time();
$before = (new DateTimeImmutable())->getTimestamp();
$date = new Carbon('1 day ago');
$after = time();
$after = (new DateTimeImmutable())->getTimestamp();
$this->assertGreaterThanOrEqual($before - 86400, $date->getTimestamp());
$this->assertLessThanOrEqual($after - 86400, $date->getTimestamp());
}

public function testConstructTimestamp()
{
$date = new Carbon(1367186296);
$this->assertSame(1367186296, $date->getTimestamp());
}

public function testMake()
{
$date1 = Carbon::make('Sunday 28 April 2013 21:58:16');
Expand Down

0 comments on commit 7ce9ddc

Please sign in to comment.