Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -17,6 +17,7 @@ use Carbon\CarbonInterval;
use Carbon\Exceptions\UnitException;
use Closure;
use DateInterval;
use DateMalformedStringException;
use ReturnTypeWillChange;
/**
@@ -60,8 +61,6 @@ trait Units
case 'millisecond':
return $this->addRealUnit('microsecond', $value * static::MICROSECONDS_PER_MILLISECOND);
break;
// @call addRealUnit
case 'second':
break;
@@ -167,7 +166,7 @@ trait Units
'weekday',
];
return \in_array($unit, $modifiableUnits) || \in_array($unit, static::$units);
return \in_array($unit, $modifiableUnits, true) || \in_array($unit, static::$units, true);
}
/**
@@ -199,7 +198,7 @@ trait Units
public function add($unit, $value = 1, $overflow = null)
{
if (\is_string($unit) && \func_num_args() === 1) {
$unit = CarbonInterval::make($unit);
$unit = CarbonInterval::make($unit, [], true);
}
if ($unit instanceof CarbonConverterInterface) {
@@ -232,6 +231,8 @@ trait Units
*/
public function addUnit($unit, $value = 1, $overflow = null)
{
$originalArgs = \func_get_args();
$date = $this;
if (!is_numeric($value) || !(float) $value) {
@@ -264,7 +265,7 @@ trait Units
/** @var static $date */
$date = $date->addDays($sign);
while (\in_array($date->dayOfWeek, $weekendDays)) {
while (\in_array($date->dayOfWeek, $weekendDays, true)) {
$date = $date->addDays($sign);
}
}
@@ -274,14 +275,14 @@ trait Units
}
$timeString = $date->toTimeString();
} elseif ($canOverflow = \in_array($unit, [
} elseif ($canOverflow = (\in_array($unit, [
'month',
'year',
]) && ($overflow === false || (
$overflow === null &&
($ucUnit = ucfirst($unit).'s') &&
!($this->{'local'.$ucUnit.'Overflow'} ?? static::{'shouldOverflow'.$ucUnit}())
))) {
)))) {
$day = $date->day;
}
@@ -304,16 +305,21 @@ trait Units
$unit = 'second';
$value = $second;
}
$date = $date->modify("$value $unit");
if (isset($timeString)) {
$date = $date->setTimeFromTimeString($timeString);
} elseif (isset($canOverflow, $day) && $canOverflow && $day !== $date->day) {
$date = $date->modify('last day of previous month');
try {
$date = $date->modify("$value $unit");
if (isset($timeString)) {
$date = $date->setTimeFromTimeString($timeString);
} elseif (isset($canOverflow, $day) && $canOverflow && $day !== $date->day) {
$date = $date->modify('last day of previous month');
}
} catch (DateMalformedStringException $ignoredException) { // @codeCoverageIgnore
$date = null; // @codeCoverageIgnore
}
if (!$date) {
throw new UnitException('Unable to add unit '.var_export(\func_get_args(), true));
throw new UnitException('Unable to add unit '.var_export($originalArgs, true));
}
return $date;
@@ -362,7 +368,7 @@ trait Units
public function sub($unit, $value = 1, $overflow = null)
{
if (\is_string($unit) && \func_num_args() === 1) {
$unit = CarbonInterval::make($unit);
$unit = CarbonInterval::make($unit, [], true);
}
if ($unit instanceof CarbonConverterInterface) {
@@ -398,7 +404,7 @@ trait Units
public function subtract($unit, $value = 1, $overflow = null)
{
if (\is_string($unit) && \func_num_args() === 1) {
$unit = CarbonInterval::make($unit);
$unit = CarbonInterval::make($unit, [], true);
}
return $this->sub($unit, $value, $overflow);