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

@@ -75,6 +75,9 @@ trait Comparison
*/
public function equalTo($date): bool
{
$this->discourageNull($date);
$this->discourageBoolean($date);
return $this == $this->resolveCarbon($date);
}
@@ -155,6 +158,9 @@ trait Comparison
*/
public function greaterThan($date): bool
{
$this->discourageNull($date);
$this->discourageBoolean($date);
return $this > $this->resolveCarbon($date);
}
@@ -216,7 +222,10 @@ trait Comparison
*/
public function greaterThanOrEqualTo($date): bool
{
return $this >= $date;
$this->discourageNull($date);
$this->discourageBoolean($date);
return $this >= $this->resolveCarbon($date);
}
/**
@@ -256,6 +265,9 @@ trait Comparison
*/
public function lessThan($date): bool
{
$this->discourageNull($date);
$this->discourageBoolean($date);
return $this < $this->resolveCarbon($date);
}
@@ -317,7 +329,10 @@ trait Comparison
*/
public function lessThanOrEqualTo($date): bool
{
return $this <= $date;
$this->discourageNull($date);
$this->discourageBoolean($date);
return $this <= $this->resolveCarbon($date);
}
/**
@@ -351,10 +366,10 @@ trait Comparison
}
if ($equal) {
return $this->greaterThanOrEqualTo($date1) && $this->lessThanOrEqualTo($date2);
return $this >= $date1 && $this <= $date2;
}
return $this->greaterThan($date1) && $this->lessThan($date2);
return $this > $date1 && $this < $date2;
}
/**
@@ -448,7 +463,7 @@ trait Comparison
*/
public function isWeekend()
{
return \in_array($this->dayOfWeek, static::$weekendDays);
return \in_array($this->dayOfWeek, static::$weekendDays, true);
}
/**
@@ -548,12 +563,17 @@ trait Comparison
}
/**
* Determines if the instance is a long year
* Determines if the instance is a long year (using calendar year).
*
* ⚠️ This method completely ignores month and day to use the numeric year number,
* it's not correct if the exact date matters. For instance as `2019-12-30` is already
* in the first week of the 2020 year, if you want to know from this date if ISO week
* year 2020 is a long year, use `isLongIsoYear` instead.
*
* @example
* ```
* Carbon::parse('2015-01-01')->isLongYear(); // true
* Carbon::parse('2016-01-01')->isLongYear(); // false
* Carbon::create(2015)->isLongYear(); // true
* Carbon::create(2016)->isLongYear(); // false
* ```
*
* @see https://en.wikipedia.org/wiki/ISO_8601#Week_dates
@@ -565,6 +585,27 @@ trait Comparison
return static::create($this->year, 12, 28, 0, 0, 0, $this->tz)->weekOfYear === 53;
}
/**
* Determines if the instance is a long year (using ISO 8601 year).
*
* @example
* ```
* Carbon::parse('2015-01-01')->isLongIsoYear(); // true
* Carbon::parse('2016-01-01')->isLongIsoYear(); // true
* Carbon::parse('2016-01-03')->isLongIsoYear(); // false
* Carbon::parse('2019-12-29')->isLongIsoYear(); // false
* Carbon::parse('2019-12-30')->isLongIsoYear(); // true
* ```
*
* @see https://en.wikipedia.org/wiki/ISO_8601#Week_dates
*
* @return bool
*/
public function isLongIsoYear()
{
return static::create($this->isoWeekYear, 12, 28, 0, 0, 0, $this->tz)->weekOfYear === 53;
}
/**
* Compares the formatted values of the two dates.
*
@@ -621,19 +662,19 @@ trait Comparison
'microsecond' => 'Y-m-d H:i:s.u',
];
if (!isset($units[$unit])) {
if (isset($this->$unit)) {
return $this->resolveCarbon($date)->$unit === $this->$unit;
}
if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) {
throw new BadComparisonUnitException($unit);
}
return false;
if (isset($units[$unit])) {
return $this->isSameAs($units[$unit], $date);
}
return $this->isSameAs($units[$unit], $date);
if (isset($this->$unit)) {
return $this->resolveCarbon($date)->$unit === $this->$unit;
}
if ($this->localStrictModeEnabled ?? static::isStrictModeEnabled()) {
throw new BadComparisonUnitException($unit);
}
return false;
}
/**
@@ -981,12 +1022,12 @@ trait Comparison
return $current->startOfMinute()->eq($other);
}
if (preg_match('/\d(h|am|pm)$/', $tester)) {
if (preg_match('/\d(?:h|am|pm)$/', $tester)) {
return $current->startOfHour()->eq($other);
}
if (preg_match(
'/^(january|february|march|april|may|june|july|august|september|october|november|december)\s+\d+$/i',
'/^(?:january|february|march|april|may|june|july|august|september|october|november|december)(?:\s+\d+)?$/i',
$tester
)) {
return $current->startOfMonth()->eq($other->startOfMonth());
@@ -1067,4 +1108,18 @@ trait Comparison
{
return $this->endOfTime ?? false;
}
private function discourageNull($value): void
{
if ($value === null) {
@trigger_error("Since 2.61.0, it's deprecated to compare a date to null, meaning of such comparison is ambiguous and will no longer be possible in 3.0.0, you should explicitly pass 'now' or make an other check to eliminate null values.", \E_USER_DEPRECATED);
}
}
private function discourageBoolean($value): void
{
if (\is_bool($value)) {
@trigger_error("Since 2.61.0, it's deprecated to compare a date to true or false, meaning of such comparison is ambiguous and will no longer be possible in 3.0.0, you should explicitly pass 'now' or make an other check to eliminate boolean values.", \E_USER_DEPRECATED);
}
}
}