Skip to content

Commit

Permalink
Add tests specifically for #2604 and #3050
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Jul 15, 2024
1 parent 4d3f401 commit 37b3bd5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/Carbon/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,23 @@ public function testPHPBug80974()
$this->assertSame(1, Carbon::parse('2018-07-01')->diffAsDateInterval(Carbon::parse('2018-07-02')->utc())->days);
}

public function testThreeMonthMinusOneDay()
{
$start = new Carbon('2022-11-11 22:29:50.000000');
$end = $start->copy()->addMonths(3);
$now = $start->copy()->addDay();

$this->assertSame(3.0, $start->diffInMonths($end));
$this->assertSame(3 - 1 / 31, $now->diffInMonths($end));

$start = new Carbon('2022-04-11 22:29:50.000000');
$end = $start->copy()->addMonths(3);
$now = $start->copy()->addDay();

$this->assertSame(3.0, $start->diffInMonths($end));
$this->assertSame(3 - 1 / 30, $now->diffInMonths($end));
}

public function testDiffWithZeroAndNonZeroMicroseconds()
{
$requestTime = new Carbon('2018-11-14 18:23:12.0 +00:00');
Expand Down
7 changes: 7 additions & 0 deletions tests/Carbon/GettersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ public function testGetAgeWithRealAge()
$this->assertSame($age, $d->age);
}

public function testAgeWithBirthdayTomorrowAndLeapYear()
{
Carbon::setTestNow('2024-07-15 22:15');

$this->assertSame(3, Carbon::parse('2020-07-16')->age);
}

public static function dataForTestQuarter(): array
{
return [
Expand Down
17 changes: 17 additions & 0 deletions tests/CarbonImmutable/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,23 @@ public function testPHPBug80974()
$this->assertSame(1, Carbon::parse('2018-07-01')->diffAsDateInterval(Carbon::parse('2018-07-02')->utc())->days);
}

public function testThreeMonthMinusOneDay()
{
$start = new Carbon('2022-11-11 22:29:50.000000');
$end = $start->addMonths(3);
$now = $start->addDay();

$this->assertSame(3.0, $start->diffInMonths($end));
$this->assertSame(3 - 1 / 31, $now->diffInMonths($end));

$start = new Carbon('2022-04-11 22:29:50.000000');
$end = $start->addMonths(3);
$now = $start->addDay();

$this->assertSame(3.0, $start->diffInMonths($end));
$this->assertSame(3 - 1 / 30, $now->diffInMonths($end));
}

public function testDiffWithZeroAndNonZeroMicroseconds()
{
$requestTime = new Carbon('2018-11-14 18:23:12.0 +00:00');
Expand Down

0 comments on commit 37b3bd5

Please sign in to comment.