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

@@ -532,6 +532,7 @@ trait Date
use Creator;
use Difference;
use Macro;
use MagicParameter;
use Modifiers;
use Mutability;
use ObjectInitialisation;
@@ -641,9 +642,11 @@ trait Date
/**
* List of minimum and maximums for each unit.
*
* @param int $daysInMonth
*
* @return array
*/
protected static function getRangesByUnit()
protected static function getRangesByUnit(int $daysInMonth = 31): array
{
return [
// @call roundUnit
@@ -651,7 +654,7 @@ trait Date
// @call roundUnit
'month' => [1, static::MONTHS_PER_YEAR],
// @call roundUnit
'day' => [1, 31],
'day' => [1, $daysInMonth],
// @call roundUnit
'hour' => [0, static::HOURS_PER_DAY - 1],
// @call roundUnit
@@ -940,7 +943,7 @@ trait Date
case $name === 'millisecond':
// @property int
case $name === 'milli':
return (int) floor($this->rawFormat('u') / 1000);
return (int) floor(((int) $this->rawFormat('u')) / 1000);
// @property int 1 through 53
case $name === 'week':
@@ -1250,7 +1253,7 @@ trait Date
protected function getTranslatedFormByRegExp($baseKey, $keySuffix, $context, $subKey, $defaultValue)
{
$key = $baseKey.$keySuffix;
$standaloneKey = "${key}_standalone";
$standaloneKey = "{$key}_standalone";
$baseTranslation = $this->getTranslationMessage($key);
if ($baseTranslation instanceof Closure) {
@@ -1259,7 +1262,7 @@ trait Date
if (
$this->getTranslationMessage("$standaloneKey.$subKey") &&
(!$context || ($regExp = $this->getTranslationMessage("${baseKey}_regexp")) && !preg_match($regExp, $context))
(!$context || (($regExp = $this->getTranslationMessage("{$baseKey}_regexp")) && !preg_match($regExp, $context)))
) {
$key = $standaloneKey;
}
@@ -1354,9 +1357,14 @@ trait Date
*/
public function weekday($value = null)
{
$dayOfWeek = ($this->dayOfWeek + 7 - (int) ($this->getTranslationMessage('first_day_of_week') ?? 0)) % 7;
if ($value === null) {
return $this->dayOfWeek;
}
return $value === null ? $dayOfWeek : $this->addDays($value - $dayOfWeek);
$firstDay = (int) ($this->getTranslationMessage('first_day_of_week') ?? 0);
$dayOfWeek = ($this->dayOfWeek + 7 - $firstDay) % 7;
return $this->addDays((($value + 7 - $firstDay) % 7) - $dayOfWeek);
}
/**
@@ -1373,6 +1381,39 @@ trait Date
return $value === null ? $dayOfWeekIso : $this->addDays($value - $dayOfWeekIso);
}
/**
* Return the number of days since the start of the week (using the current locale or the first parameter
* if explicitly given).
*
* @param int|null $weekStartsAt optional start allow you to specify the day of week to use to start the week,
* if not provided, start of week is inferred from the locale
* (Sunday for en_US, Monday for de_DE, etc.)
*
* @return int
*/
public function getDaysFromStartOfWeek(int $weekStartsAt = null): int
{
$firstDay = (int) ($weekStartsAt ?? $this->getTranslationMessage('first_day_of_week') ?? 0);
return ($this->dayOfWeek + 7 - $firstDay) % 7;
}
/**
* Set the day (keeping the current time) to the start of the week + the number of days passed as the first
* parameter. First day of week is driven by the locale unless explicitly set with the second parameter.
*
* @param int $numberOfDays number of days to add after the start of the current week
* @param int|null $weekStartsAt optional start allow you to specify the day of week to use to start the week,
* if not provided, start of week is inferred from the locale
* (Sunday for en_US, Monday for de_DE, etc.)
*
* @return static
*/
public function setDaysFromStartOfWeek(int $numberOfDays, int $weekStartsAt = null)
{
return $this->addDays($numberOfDays - $this->getDaysFromStartOfWeek($weekStartsAt));
}
/**
* Set any unit to a new value without overflowing current other unit given.
*
@@ -1848,9 +1889,18 @@ trait Date
$format = preg_replace('#(?<!%)((?:%%)*)%e#', '\1%#d', $format); // @codeCoverageIgnore
}
$formatted = strftime($format, strtotime($this->toDateTimeString()));
$time = strtotime($this->toDateTimeString());
$formatted = ($this->localStrictModeEnabled ?? static::isStrictModeEnabled())
? strftime($format, $time)
: @strftime($format, $time);
return static::$utf8 ? utf8_encode($formatted) : $formatted;
return static::$utf8
? (
\function_exists('mb_convert_encoding')
? mb_convert_encoding($formatted, 'UTF-8', mb_list_encodings())
: utf8_encode($formatted)
)
: $formatted;
}
/**
@@ -1869,6 +1919,10 @@ trait Date
'LL' => $this->getTranslationMessage('formats.LL', $locale, 'MMMM D, YYYY'),
'LLL' => $this->getTranslationMessage('formats.LLL', $locale, 'MMMM D, YYYY h:mm A'),
'LLLL' => $this->getTranslationMessage('formats.LLLL', $locale, 'dddd, MMMM D, YYYY h:mm A'),
'l' => $this->getTranslationMessage('formats.l', $locale),
'll' => $this->getTranslationMessage('formats.ll', $locale),
'lll' => $this->getTranslationMessage('formats.lll', $locale),
'llll' => $this->getTranslationMessage('formats.llll', $locale),
];
}
@@ -2152,7 +2206,7 @@ trait Date
$input = mb_substr($format, $i);
if (preg_match('/^(LTS|LT|[Ll]{1,4})/', $input, $match)) {
if (preg_match('/^(LTS|LT|l{1,4}|L{1,4})/', $input, $match)) {
if ($formats === null) {
$formats = $this->getIsoFormats();
}
@@ -2256,6 +2310,7 @@ trait Date
'c' => true,
'r' => true,
'U' => true,
'T' => true,
];
}
@@ -2359,7 +2414,7 @@ trait Date
$symbol = $second < 0 ? '-' : '+';
$minute = abs($second) / static::SECONDS_PER_MINUTE;
$hour = str_pad((string) floor($minute / static::MINUTES_PER_HOUR), 2, '0', STR_PAD_LEFT);
$minute = str_pad((string) ($minute % static::MINUTES_PER_HOUR), 2, '0', STR_PAD_LEFT);
$minute = str_pad((string) (((int) $minute) % static::MINUTES_PER_HOUR), 2, '0', STR_PAD_LEFT);
return "$symbol$hour$separator$minute";
}
@@ -2479,7 +2534,7 @@ trait Date
return 'millennia';
}
return "${unit}s";
return "{$unit}s";
}
protected function executeCallable($macro, ...$parameters)
@@ -2566,7 +2621,7 @@ trait Date
if (str_starts_with($unit, 'is')) {
$word = substr($unit, 2);
if (\in_array($word, static::$days)) {
if (\in_array($word, static::$days, true)) {
return $this->isDayOfWeek($word);
}
@@ -2594,7 +2649,7 @@ trait Date
$unit = strtolower(substr($unit, 3));
}
if (\in_array($unit, static::$units)) {
if (\in_array($unit, static::$units, true)) {
return $this->setUnit($unit, ...$parameters);
}
@@ -2604,7 +2659,7 @@ trait Date
if (str_starts_with($unit, 'Real')) {
$unit = static::singularUnit(substr($unit, 4));
return $this->{"${action}RealUnit"}($unit, ...$parameters);
return $this->{"{$action}RealUnit"}($unit, ...$parameters);
}
if (preg_match('/^(Month|Quarter|Year|Decade|Century|Centurie|Millennium|Millennia)s?(No|With|Without|WithNo)Overflow$/', $unit, $match)) {
@@ -2616,7 +2671,7 @@ trait Date
}
if (static::isModifiableUnit($unit)) {
return $this->{"${action}Unit"}($unit, $parameters[0] ?? 1, $overflow);
return $this->{"{$action}Unit"}($unit, $this->getMagicParameter($parameters, 0, 'value', 1), $overflow);
}
$sixFirstLetters = substr($unit, 0, 6);
@@ -2655,7 +2710,11 @@ trait Date
try {
$unit = static::singularUnit(substr($method, 0, -5));
return $this->range($parameters[0] ?? $this, $parameters[1] ?? 1, $unit);
return $this->range(
$this->getMagicParameter($parameters, 0, 'endDate', $this),
$this->getMagicParameter($parameters, 1, 'factor', 1),
$unit
);
} catch (InvalidArgumentException $exception) {
// Try macros
}