Skip to content

Commit

Permalink
#2035 Disable NO_ZERO_DIFF option by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed May 6, 2020
1 parent 3f9ca81 commit c5ed301
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/Carbon/Traits/Difference.php
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,6 @@ public function timespan($other = null, $timezone = null)
return $this->diffForHumans($other, [
'join' => ', ',
'syntax' => CarbonInterface::DIFF_ABSOLUTE,
'options' => CarbonInterface::NO_ZERO_DIFF,
'parts' => -1,
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Carbon/Traits/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ trait Localization
*
* @var int
*/
protected static $humanDiffOptions = CarbonInterface::NO_ZERO_DIFF;
protected static $humanDiffOptions = 0;

/**
* @deprecated To avoid conflict between different third-party libraries, static setters should not be used.
Expand Down
8 changes: 4 additions & 4 deletions tests/Carbon/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public function testDiffInSecondsWithTimezonesAndVsDefault()
public function testDiffForHumansNowAndSecond()
{
$this->wrapWithTestNow(function () {
$this->assertSame('1 second ago', Carbon::now()->diffForHumans());
$this->assertSame('0 seconds ago', Carbon::now()->diffForHumans());
});
}

Expand All @@ -553,7 +553,7 @@ public function testDiffForHumansNowAndSecondWithTimezone()
$vanNow = Carbon::now('America/Vancouver');
$hereNow = $vanNow->copy()->setTimezone(Carbon::now()->tz);
$this->wrapWithTestNow(function () use ($vanNow) {
$this->assertSame('1 second ago', $vanNow->diffForHumans());
$this->assertSame('0 seconds ago', $vanNow->diffForHumans());
}, $hereNow);
}

Expand Down Expand Up @@ -1308,10 +1308,10 @@ public function testDiffOptions()
$this->assertSame(8, Carbon::TWO_DAY_WORDS);

$options = Carbon::getHumanDiffOptions();
$this->assertSame(1, $options);
$this->assertSame(0, $options);

$date = Carbon::create(2018, 3, 12, 2, 5, 6, 'UTC');
$this->assertSame('1 second before', $date->diffForHumans($date));
$this->assertSame('0 seconds before', $date->diffForHumans($date));

Carbon::setHumanDiffOptions(0);
$this->assertSame(0, Carbon::getHumanDiffOptions());
Expand Down
8 changes: 4 additions & 4 deletions tests/CarbonImmutable/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public function testDiffInSecondsWithTimezonesAndVsDefault()
public function testDiffForHumansNowAndSecond()
{
$this->wrapWithTestNow(function () {
$this->assertSame('1 second ago', Carbon::now()->diffForHumans());
$this->assertSame('0 seconds ago', Carbon::now()->diffForHumans());
});
}

Expand All @@ -521,7 +521,7 @@ public function testDiffForHumansNowAndSecondWithTimezone()
$vanNow = Carbon::now('America/Vancouver');
$hereNow = $vanNow->copy()->setTimezone(Carbon::now()->tz);
$this->wrapWithTestNow(function () use ($vanNow) {
$this->assertSame('1 second ago', $vanNow->diffForHumans());
$this->assertSame('0 seconds ago', $vanNow->diffForHumans());
}, $hereNow);
}

Expand Down Expand Up @@ -1236,10 +1236,10 @@ public function testDiffOptions()
$this->assertSame(16, Carbon::SEQUENTIAL_PARTS_ONLY);

$options = Carbon::getHumanDiffOptions();
$this->assertSame(1, $options);
$this->assertSame(0, $options);

$date = Carbon::create(2018, 3, 12, 2, 5, 6, 'UTC');
$this->assertSame('1 second before', $date->diffForHumans($date));
$this->assertSame('0 seconds before', $date->diffForHumans($date));

Carbon::setHumanDiffOptions(0);
$this->assertSame(0, Carbon::getHumanDiffOptions());
Expand Down
2 changes: 1 addition & 1 deletion tests/CommonTraits/MacroContextNestingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getMacroableClasses()
return [
[Carbon::class, Carbon::parse('2010-05-23'), null],
[CarbonImmutable::class, CarbonImmutable::parse('2010-05-23'), null],
[CarbonInterval::class, CarbonInterval::make('P1M6D'), strval(CarbonInterval::second())],
[CarbonInterval::class, CarbonInterval::make('P1M6D'), strval(CarbonInterval::seconds(0))],
[CarbonPeriod::class, CarbonPeriod::create('2010-08-23', '2010-10-02'), null],
];
}
Expand Down

0 comments on commit c5ed301

Please sign in to comment.