Skip to content

Commit

Permalink
Merge pull request #343 from cakephp/tests-pr323
Browse files Browse the repository at this point in the history
 Switch human diff to months when interval is 2+ months
  • Loading branch information
markstory authored Nov 8, 2022
2 parents 7066789 + 91f490e commit a21b7b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/DifferenceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function diffForHumans(
$unit = 'year';
$count = $diffInterval->y;
break;
case $diffInterval->days >= ChronosInterface::DAYS_PER_WEEK * 8:
case $diffInterval->m >= 2:
$unit = 'month';
$count = $diffInterval->m;
break;
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/DateTime/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ public function diffForHumansProvider()
[$now, $now->addYears(11), '11 years before'],
[$now, $now->addYears(1), '1 year before'],
[$now, $now->addMonths(11), '11 months before'],
[$now, $now->addMonths(1), '4 weeks before'],
[$now, $now->addDays(23), '3 weeks before'],
[$now, $now->addMonths(2), '2 months before'],
[$now, $now->addWeeks(8), '8 weeks before'],
[$now, $now->addDays(21), '3 weeks before'],
[$now, $now->addDays(20), '20 days before'],
[$now, $now->addDays(8), '8 days before'],
Expand All @@ -800,8 +800,8 @@ public function diffForHumansProvider()
[$now, $now->subYears(11), '11 years after'],
[$now, $now->subYears(1), '1 year after'],
[$now, $now->subMonths(11), '11 months after'],
[$now, $now->subMonths(1), '4 weeks after'],
[$now, $now->subDays(23), '3 weeks after'],
[$now, $now->subMonths(2), '2 months after'],
[$now, $now->subWeeks(8), '8 weeks after'],
[$now, $now->subDays(21), '3 weeks after'],
[$now, $now->subDays(20), '20 days after'],
[$now, $now->subDays(8), '8 days after'],
Expand Down

0 comments on commit a21b7b6

Please sign in to comment.