upgrade to laravel 7 and set branch to v2
This commit is contained in:
+14
-10
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
@@ -18,9 +20,8 @@ namespace Cake\Chronos;
|
||||
* Provides a swappable component for other libraries to leverage.
|
||||
* when localizing or customizing the difference output.
|
||||
*/
|
||||
class DifferenceFormatter
|
||||
class DifferenceFormatter implements DifferenceFormatterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* The text translator object
|
||||
*
|
||||
@@ -33,7 +34,7 @@ class DifferenceFormatter
|
||||
*
|
||||
* @param \Cake\Chronos\Translator|null $translate The text translator object.
|
||||
*/
|
||||
public function __construct($translate = null)
|
||||
public function __construct(?Translator $translate = null)
|
||||
{
|
||||
$this->translate = $translate ?: new Translator();
|
||||
}
|
||||
@@ -47,8 +48,11 @@ class DifferenceFormatter
|
||||
* @return string The difference between the two days in a human readable format
|
||||
* @see \Cake\Chronos\ChronosInterface::diffForHumans
|
||||
*/
|
||||
public function diffForHumans(ChronosInterface $date, ChronosInterface $other = null, $absolute = false)
|
||||
{
|
||||
public function diffForHumans(
|
||||
ChronosInterface $date,
|
||||
?ChronosInterface $other = null,
|
||||
bool $absolute = false
|
||||
): string {
|
||||
$isNow = $other === null;
|
||||
if ($isNow) {
|
||||
$other = $date->now($date->tz);
|
||||
@@ -56,15 +60,15 @@ class DifferenceFormatter
|
||||
$diffInterval = $date->diff($other);
|
||||
|
||||
switch (true) {
|
||||
case ($diffInterval->y > 0):
|
||||
case $diffInterval->y > 0:
|
||||
$unit = 'year';
|
||||
$count = $diffInterval->y;
|
||||
break;
|
||||
case ($diffInterval->m > 0):
|
||||
case $diffInterval->m > 0:
|
||||
$unit = 'month';
|
||||
$count = $diffInterval->m;
|
||||
break;
|
||||
case ($diffInterval->d > 0):
|
||||
case $diffInterval->d > 0:
|
||||
$unit = 'day';
|
||||
$count = $diffInterval->d;
|
||||
if ($count >= ChronosInterface::DAYS_PER_WEEK) {
|
||||
@@ -72,11 +76,11 @@ class DifferenceFormatter
|
||||
$count = (int)($count / ChronosInterface::DAYS_PER_WEEK);
|
||||
}
|
||||
break;
|
||||
case ($diffInterval->h > 0):
|
||||
case $diffInterval->h > 0:
|
||||
$unit = 'hour';
|
||||
$count = $diffInterval->h;
|
||||
break;
|
||||
case ($diffInterval->i > 0):
|
||||
case $diffInterval->i > 0:
|
||||
$unit = 'minute';
|
||||
$count = $diffInterval->i;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user