updated composer

This commit is contained in:
2021-05-18 13:47:03 +00:00
parent e248cd036c
commit ba92152daa
1187 changed files with 20804 additions and 22320 deletions

View File

@@ -40,7 +40,7 @@
"phpmd/phpmd": "^2.9",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.54",
"phpunit/phpunit": "^7.5 || ^8.0",
"phpunit/phpunit": "^7.5.20 || ^8.5.14",
"squizlabs/php_codesniffer": "^3.4"
},
"autoload": {

View File

@@ -509,5 +509,64 @@ use DateTimeZone;
*/
class CarbonImmutable extends DateTimeImmutable implements CarbonInterface
{
use Date;
use Date {
__clone as dateTraitClone;
}
public function __clone()
{
$this->dateTraitClone();
$this->endOfTime = false;
$this->startOfTime = false;
}
/**
* Create a very old date representing start of time.
*
* @return static
*/
public static function startOfTime(): self
{
$date = static::parse('0001-01-01')->years(self::getStartOfTimeYear());
$date->startOfTime = true;
return $date;
}
/**
* Create a very far date representing end of time.
*
* @return static
*/
public static function endOfTime(): self
{
$date = static::parse('9999-12-31 23:59:59.999999')->years(self::getEndOfTimeYear());
$date->endOfTime = true;
return $date;
}
/**
* @codeCoverageIgnore
*/
private static function getEndOfTimeYear(): int
{
if (version_compare(PHP_VERSION, '7.3.0-dev', '<')) {
return 145261681241552;
}
return PHP_INT_MAX;
}
/**
* @codeCoverageIgnore
*/
private static function getStartOfTimeYear(): int
{
if (version_compare(PHP_VERSION, '7.3.0-dev', '<')) {
return -135908816449551;
}
return max(PHP_INT_MIN, -9223372036854773760);
}
}

View File

@@ -668,8 +668,8 @@ interface CarbonInterface extends DateTimeInterface, JsonSerializable
* Please see the testing aids section (specifically static::setTestNow())
* for more on the possibility of this constructor returning a test instance.
*
* @param string|null $time
* @param DateTimeZone|string|null $tz
* @param DateTimeInterface|string|null $time
* @param DateTimeZone|string|null $tz
*
* @throws InvalidFormatException
*/
@@ -888,7 +888,10 @@ interface CarbonInterface extends DateTimeInterface, JsonSerializable
public function betweenIncluded($date1, $date2): bool;
/**
* Returns either the close date "Friday 15h30", or a calendar date "10/09/2017" is farthest than 7 days from now.
* Returns either day of week + time (e.g. "Last Friday at 3:30 PM") if reference time is within 7 days,
* or a calendar date (e.g. "10/29/2017") otherwise.
*
* Language, date and time formats will change according to the current locale.
*
* @param Carbon|\DateTimeInterface|string|null $referenceTime
* @param array $formats
@@ -2626,6 +2629,13 @@ interface CarbonInterface extends DateTimeInterface, JsonSerializable
*/
public function isEndOfDay($checkMicroseconds = false);
/**
* Returns true if the date was created using CarbonImmutable::endOfTime()
*
* @return bool
*/
public function isEndOfTime(): bool;
/**
* Determines if the instance is in the future, ie. greater (after) than now.
*
@@ -2836,6 +2846,13 @@ interface CarbonInterface extends DateTimeInterface, JsonSerializable
*/
public function isStartOfDay($checkMicroseconds = false);
/**
* Returns true if the date was created using CarbonImmutable::startOfTime()
*
* @return bool
*/
public function isStartOfTime(): bool;
/**
* Returns true if the strict mode is globally in use, false else.
* (It can be overridden in specific instances.)
@@ -4886,11 +4903,11 @@ interface CarbonInterface extends DateTimeInterface, JsonSerializable
/**
* Returns the minutes offset to UTC if no arguments passed, else set the timezone with given minutes shift passed.
*
* @param int|null $offset
* @param int|null $minuteOffset
*
* @return int|static
*/
public function utcOffset(int $offset = null);
public function utcOffset(int $minuteOffset = null);
/**
* Returns the milliseconds timestamps used amongst other by Date javascript objects.

View File

@@ -79,84 +79,102 @@ use Throwable;
* @method static CarbonInterval millisecond($milliseconds = 1) Alias for milliseconds()
* @method static CarbonInterval microseconds($microseconds = 1) Create instance specifying a number of microseconds or modify the number of microseconds if called on an instance.
* @method static CarbonInterval microsecond($microseconds = 1) Alias for microseconds()
* @method $this roundYear(float $precision = 1, string $function = "round") Round the current instance year with given precision using the given function.
* @method $this roundYears(float $precision = 1, string $function = "round") Round the current instance year with given precision using the given function.
* @method $this floorYear(float $precision = 1) Truncate the current instance year with given precision.
* @method $this floorYears(float $precision = 1) Truncate the current instance year with given precision.
* @method $this ceilYear(float $precision = 1) Ceil the current instance year with given precision.
* @method $this ceilYears(float $precision = 1) Ceil the current instance year with given precision.
* @method $this roundMonth(float $precision = 1, string $function = "round") Round the current instance month with given precision using the given function.
* @method $this roundMonths(float $precision = 1, string $function = "round") Round the current instance month with given precision using the given function.
* @method $this floorMonth(float $precision = 1) Truncate the current instance month with given precision.
* @method $this floorMonths(float $precision = 1) Truncate the current instance month with given precision.
* @method $this ceilMonth(float $precision = 1) Ceil the current instance month with given precision.
* @method $this ceilMonths(float $precision = 1) Ceil the current instance month with given precision.
* @method $this roundWeek(float $precision = 1, string $function = "round") Round the current instance day with given precision using the given function.
* @method $this roundWeeks(float $precision = 1, string $function = "round") Round the current instance day with given precision using the given function.
* @method $this floorWeek(float $precision = 1) Truncate the current instance day with given precision.
* @method $this floorWeeks(float $precision = 1) Truncate the current instance day with given precision.
* @method $this ceilWeek(float $precision = 1) Ceil the current instance day with given precision.
* @method $this ceilWeeks(float $precision = 1) Ceil the current instance day with given precision.
* @method $this roundDay(float $precision = 1, string $function = "round") Round the current instance day with given precision using the given function.
* @method $this roundDays(float $precision = 1, string $function = "round") Round the current instance day with given precision using the given function.
* @method $this floorDay(float $precision = 1) Truncate the current instance day with given precision.
* @method $this floorDays(float $precision = 1) Truncate the current instance day with given precision.
* @method $this ceilDay(float $precision = 1) Ceil the current instance day with given precision.
* @method $this ceilDays(float $precision = 1) Ceil the current instance day with given precision.
* @method $this roundHour(float $precision = 1, string $function = "round") Round the current instance hour with given precision using the given function.
* @method $this roundHours(float $precision = 1, string $function = "round") Round the current instance hour with given precision using the given function.
* @method $this floorHour(float $precision = 1) Truncate the current instance hour with given precision.
* @method $this floorHours(float $precision = 1) Truncate the current instance hour with given precision.
* @method $this ceilHour(float $precision = 1) Ceil the current instance hour with given precision.
* @method $this ceilHours(float $precision = 1) Ceil the current instance hour with given precision.
* @method $this roundMinute(float $precision = 1, string $function = "round") Round the current instance minute with given precision using the given function.
* @method $this roundMinutes(float $precision = 1, string $function = "round") Round the current instance minute with given precision using the given function.
* @method $this floorMinute(float $precision = 1) Truncate the current instance minute with given precision.
* @method $this floorMinutes(float $precision = 1) Truncate the current instance minute with given precision.
* @method $this ceilMinute(float $precision = 1) Ceil the current instance minute with given precision.
* @method $this ceilMinutes(float $precision = 1) Ceil the current instance minute with given precision.
* @method $this roundSecond(float $precision = 1, string $function = "round") Round the current instance second with given precision using the given function.
* @method $this roundSeconds(float $precision = 1, string $function = "round") Round the current instance second with given precision using the given function.
* @method $this floorSecond(float $precision = 1) Truncate the current instance second with given precision.
* @method $this floorSeconds(float $precision = 1) Truncate the current instance second with given precision.
* @method $this ceilSecond(float $precision = 1) Ceil the current instance second with given precision.
* @method $this ceilSeconds(float $precision = 1) Ceil the current instance second with given precision.
* @method $this roundMillennium(float $precision = 1, string $function = "round") Round the current instance millennium with given precision using the given function.
* @method $this roundMillennia(float $precision = 1, string $function = "round") Round the current instance millennium with given precision using the given function.
* @method $this floorMillennium(float $precision = 1) Truncate the current instance millennium with given precision.
* @method $this floorMillennia(float $precision = 1) Truncate the current instance millennium with given precision.
* @method $this ceilMillennium(float $precision = 1) Ceil the current instance millennium with given precision.
* @method $this ceilMillennia(float $precision = 1) Ceil the current instance millennium with given precision.
* @method $this roundCentury(float $precision = 1, string $function = "round") Round the current instance century with given precision using the given function.
* @method $this roundCenturies(float $precision = 1, string $function = "round") Round the current instance century with given precision using the given function.
* @method $this floorCentury(float $precision = 1) Truncate the current instance century with given precision.
* @method $this floorCenturies(float $precision = 1) Truncate the current instance century with given precision.
* @method $this ceilCentury(float $precision = 1) Ceil the current instance century with given precision.
* @method $this ceilCenturies(float $precision = 1) Ceil the current instance century with given precision.
* @method $this roundDecade(float $precision = 1, string $function = "round") Round the current instance decade with given precision using the given function.
* @method $this roundDecades(float $precision = 1, string $function = "round") Round the current instance decade with given precision using the given function.
* @method $this floorDecade(float $precision = 1) Truncate the current instance decade with given precision.
* @method $this floorDecades(float $precision = 1) Truncate the current instance decade with given precision.
* @method $this ceilDecade(float $precision = 1) Ceil the current instance decade with given precision.
* @method $this ceilDecades(float $precision = 1) Ceil the current instance decade with given precision.
* @method $this roundQuarter(float $precision = 1, string $function = "round") Round the current instance quarter with given precision using the given function.
* @method $this roundQuarters(float $precision = 1, string $function = "round") Round the current instance quarter with given precision using the given function.
* @method $this floorQuarter(float $precision = 1) Truncate the current instance quarter with given precision.
* @method $this floorQuarters(float $precision = 1) Truncate the current instance quarter with given precision.
* @method $this ceilQuarter(float $precision = 1) Ceil the current instance quarter with given precision.
* @method $this ceilQuarters(float $precision = 1) Ceil the current instance quarter with given precision.
* @method $this roundMillisecond(float $precision = 1, string $function = "round") Round the current instance millisecond with given precision using the given function.
* @method $this roundMilliseconds(float $precision = 1, string $function = "round") Round the current instance millisecond with given precision using the given function.
* @method $this floorMillisecond(float $precision = 1) Truncate the current instance millisecond with given precision.
* @method $this floorMilliseconds(float $precision = 1) Truncate the current instance millisecond with given precision.
* @method $this ceilMillisecond(float $precision = 1) Ceil the current instance millisecond with given precision.
* @method $this ceilMilliseconds(float $precision = 1) Ceil the current instance millisecond with given precision.
* @method $this roundMicrosecond(float $precision = 1, string $function = "round") Round the current instance microsecond with given precision using the given function.
* @method $this roundMicroseconds(float $precision = 1, string $function = "round") Round the current instance microsecond with given precision using the given function.
* @method $this floorMicrosecond(float $precision = 1) Truncate the current instance microsecond with given precision.
* @method $this floorMicroseconds(float $precision = 1) Truncate the current instance microsecond with given precision.
* @method $this ceilMicrosecond(float $precision = 1) Ceil the current instance microsecond with given precision.
* @method $this ceilMicroseconds(float $precision = 1) Ceil the current instance microsecond with given precision.
* @method $this addYears(int $years) Add given number of years to the current interval
* @method $this subYears(int $years) Subtract given number of years to the current interval
* @method $this addMonths(int $months) Add given number of months to the current interval
* @method $this subMonths(int $months) Subtract given number of months to the current interval
* @method $this addWeeks(int|float $weeks) Add given number of weeks to the current interval
* @method $this subWeeks(int|float $weeks) Subtract given number of weeks to the current interval
* @method $this addDays(int|float $days) Add given number of days to the current interval
* @method $this subDays(int|float $days) Subtract given number of days to the current interval
* @method $this addHours(int|float $hours) Add given number of hours to the current interval
* @method $this subHours(int|float $hours) Subtract given number of hours to the current interval
* @method $this addMinutes(int|float $minutes) Add given number of minutes to the current interval
* @method $this subMinutes(int|float $minutes) Subtract given number of minutes to the current interval
* @method $this addSeconds(int|float $seconds) Add given number of seconds to the current interval
* @method $this subSeconds(int|float $seconds) Subtract given number of seconds to the current interval
* @method $this addMilliseconds(int|float $milliseconds) Add given number of milliseconds to the current interval
* @method $this subMilliseconds(int|float $milliseconds) Subtract given number of milliseconds to the current interval
* @method $this addMicroseconds(int|float $microseconds) Add given number of microseconds to the current interval
* @method $this subMicroseconds(int|float $microseconds) Subtract given number of microseconds to the current interval
* @method $this roundYear(int|float $precision = 1, string $function = "round") Round the current instance year with given precision using the given function.
* @method $this roundYears(int|float $precision = 1, string $function = "round") Round the current instance year with given precision using the given function.
* @method $this floorYear(int|float $precision = 1) Truncate the current instance year with given precision.
* @method $this floorYears(int|float $precision = 1) Truncate the current instance year with given precision.
* @method $this ceilYear(int|float $precision = 1) Ceil the current instance year with given precision.
* @method $this ceilYears(int|float $precision = 1) Ceil the current instance year with given precision.
* @method $this roundMonth(int|float $precision = 1, string $function = "round") Round the current instance month with given precision using the given function.
* @method $this roundMonths(int|float $precision = 1, string $function = "round") Round the current instance month with given precision using the given function.
* @method $this floorMonth(int|float $precision = 1) Truncate the current instance month with given precision.
* @method $this floorMonths(int|float $precision = 1) Truncate the current instance month with given precision.
* @method $this ceilMonth(int|float $precision = 1) Ceil the current instance month with given precision.
* @method $this ceilMonths(int|float $precision = 1) Ceil the current instance month with given precision.
* @method $this roundWeek(int|float $precision = 1, string $function = "round") Round the current instance day with given precision using the given function.
* @method $this roundWeeks(int|float $precision = 1, string $function = "round") Round the current instance day with given precision using the given function.
* @method $this floorWeek(int|float $precision = 1) Truncate the current instance day with given precision.
* @method $this floorWeeks(int|float $precision = 1) Truncate the current instance day with given precision.
* @method $this ceilWeek(int|float $precision = 1) Ceil the current instance day with given precision.
* @method $this ceilWeeks(int|float $precision = 1) Ceil the current instance day with given precision.
* @method $this roundDay(int|float $precision = 1, string $function = "round") Round the current instance day with given precision using the given function.
* @method $this roundDays(int|float $precision = 1, string $function = "round") Round the current instance day with given precision using the given function.
* @method $this floorDay(int|float $precision = 1) Truncate the current instance day with given precision.
* @method $this floorDays(int|float $precision = 1) Truncate the current instance day with given precision.
* @method $this ceilDay(int|float $precision = 1) Ceil the current instance day with given precision.
* @method $this ceilDays(int|float $precision = 1) Ceil the current instance day with given precision.
* @method $this roundHour(int|float $precision = 1, string $function = "round") Round the current instance hour with given precision using the given function.
* @method $this roundHours(int|float $precision = 1, string $function = "round") Round the current instance hour with given precision using the given function.
* @method $this floorHour(int|float $precision = 1) Truncate the current instance hour with given precision.
* @method $this floorHours(int|float $precision = 1) Truncate the current instance hour with given precision.
* @method $this ceilHour(int|float $precision = 1) Ceil the current instance hour with given precision.
* @method $this ceilHours(int|float $precision = 1) Ceil the current instance hour with given precision.
* @method $this roundMinute(int|float $precision = 1, string $function = "round") Round the current instance minute with given precision using the given function.
* @method $this roundMinutes(int|float $precision = 1, string $function = "round") Round the current instance minute with given precision using the given function.
* @method $this floorMinute(int|float $precision = 1) Truncate the current instance minute with given precision.
* @method $this floorMinutes(int|float $precision = 1) Truncate the current instance minute with given precision.
* @method $this ceilMinute(int|float $precision = 1) Ceil the current instance minute with given precision.
* @method $this ceilMinutes(int|float $precision = 1) Ceil the current instance minute with given precision.
* @method $this roundSecond(int|float $precision = 1, string $function = "round") Round the current instance second with given precision using the given function.
* @method $this roundSeconds(int|float $precision = 1, string $function = "round") Round the current instance second with given precision using the given function.
* @method $this floorSecond(int|float $precision = 1) Truncate the current instance second with given precision.
* @method $this floorSeconds(int|float $precision = 1) Truncate the current instance second with given precision.
* @method $this ceilSecond(int|float $precision = 1) Ceil the current instance second with given precision.
* @method $this ceilSeconds(int|float $precision = 1) Ceil the current instance second with given precision.
* @method $this roundMillennium(int|float $precision = 1, string $function = "round") Round the current instance millennium with given precision using the given function.
* @method $this roundMillennia(int|float $precision = 1, string $function = "round") Round the current instance millennium with given precision using the given function.
* @method $this floorMillennium(int|float $precision = 1) Truncate the current instance millennium with given precision.
* @method $this floorMillennia(int|float $precision = 1) Truncate the current instance millennium with given precision.
* @method $this ceilMillennium(int|float $precision = 1) Ceil the current instance millennium with given precision.
* @method $this ceilMillennia(int|float $precision = 1) Ceil the current instance millennium with given precision.
* @method $this roundCentury(int|float $precision = 1, string $function = "round") Round the current instance century with given precision using the given function.
* @method $this roundCenturies(int|float $precision = 1, string $function = "round") Round the current instance century with given precision using the given function.
* @method $this floorCentury(int|float $precision = 1) Truncate the current instance century with given precision.
* @method $this floorCenturies(int|float $precision = 1) Truncate the current instance century with given precision.
* @method $this ceilCentury(int|float $precision = 1) Ceil the current instance century with given precision.
* @method $this ceilCenturies(int|float $precision = 1) Ceil the current instance century with given precision.
* @method $this roundDecade(int|float $precision = 1, string $function = "round") Round the current instance decade with given precision using the given function.
* @method $this roundDecades(int|float $precision = 1, string $function = "round") Round the current instance decade with given precision using the given function.
* @method $this floorDecade(int|float $precision = 1) Truncate the current instance decade with given precision.
* @method $this floorDecades(int|float $precision = 1) Truncate the current instance decade with given precision.
* @method $this ceilDecade(int|float $precision = 1) Ceil the current instance decade with given precision.
* @method $this ceilDecades(int|float $precision = 1) Ceil the current instance decade with given precision.
* @method $this roundQuarter(int|float $precision = 1, string $function = "round") Round the current instance quarter with given precision using the given function.
* @method $this roundQuarters(int|float $precision = 1, string $function = "round") Round the current instance quarter with given precision using the given function.
* @method $this floorQuarter(int|float $precision = 1) Truncate the current instance quarter with given precision.
* @method $this floorQuarters(int|float $precision = 1) Truncate the current instance quarter with given precision.
* @method $this ceilQuarter(int|float $precision = 1) Ceil the current instance quarter with given precision.
* @method $this ceilQuarters(int|float $precision = 1) Ceil the current instance quarter with given precision.
* @method $this roundMillisecond(int|float $precision = 1, string $function = "round") Round the current instance millisecond with given precision using the given function.
* @method $this roundMilliseconds(int|float $precision = 1, string $function = "round") Round the current instance millisecond with given precision using the given function.
* @method $this floorMillisecond(int|float $precision = 1) Truncate the current instance millisecond with given precision.
* @method $this floorMilliseconds(int|float $precision = 1) Truncate the current instance millisecond with given precision.
* @method $this ceilMillisecond(int|float $precision = 1) Ceil the current instance millisecond with given precision.
* @method $this ceilMilliseconds(int|float $precision = 1) Ceil the current instance millisecond with given precision.
* @method $this roundMicrosecond(int|float $precision = 1, string $function = "round") Round the current instance microsecond with given precision using the given function.
* @method $this roundMicroseconds(int|float $precision = 1, string $function = "round") Round the current instance microsecond with given precision using the given function.
* @method $this floorMicrosecond(int|float $precision = 1) Truncate the current instance microsecond with given precision.
* @method $this floorMicroseconds(int|float $precision = 1) Truncate the current instance microsecond with given precision.
* @method $this ceilMicrosecond(int|float $precision = 1) Ceil the current instance microsecond with given precision.
* @method $this ceilMicroseconds(int|float $precision = 1) Ceil the current instance microsecond with given precision.
*/
class CarbonInterval extends DateInterval implements CarbonConverterInterface
{
@@ -911,7 +929,7 @@ class CarbonInterval extends DateInterval implements CarbonConverterInterface
protected static function makeFromString(string $interval)
{
$interval = trim($interval);
$interval = preg_replace('/\s+/', ' ', trim($interval));
if (preg_match('/^P[T0-9]/', $interval)) {
return new static($interval);
@@ -1282,6 +1300,10 @@ class CarbonInterval extends DateInterval implements CarbonConverterInterface
return $roundedValue;
}
if (preg_match('/^(?<method>add|sub)(?<unit>[A-Z].*)$/', $method, $match)) {
return $this->{$match['method']}($parameters[0], $match['unit']);
}
try {
$this->set($method, \count($parameters) === 0 ? 1 : $parameters[0]);
} catch (UnknownSetterException $exception) {
@@ -1781,9 +1803,9 @@ class CarbonInterval extends DateInterval implements CarbonConverterInterface
* Add the passed interval to the current instance.
*
* @param string|DateInterval $unit
* @param int $value
* @param int|float $value
*
* @return static
* @return $this
*/
public function add($unit, $value = 1)
{
@@ -1824,9 +1846,9 @@ class CarbonInterval extends DateInterval implements CarbonConverterInterface
* Subtract the passed interval to the current instance.
*
* @param string|DateInterval $unit
* @param int $value
* @param int|float $value
*
* @return static
* @return $this
*/
public function sub($unit, $value = 1)
{
@@ -1841,15 +1863,75 @@ class CarbonInterval extends DateInterval implements CarbonConverterInterface
* Subtract the passed interval to the current instance.
*
* @param string|DateInterval $unit
* @param int $value
* @param int|float $value
*
* @return static
* @return $this
*/
public function subtract($unit, $value = 1)
{
return $this->sub($unit, $value);
}
/**
* Add given parameters to the current interval.
*
* @param int $years
* @param int $months
* @param int|float $weeks
* @param int|float $days
* @param int|float $hours
* @param int|float $minutes
* @param int|float $seconds
* @param int|float $microseconds
*
* @return $this
*/
public function plus(
$years = 0,
$months = 0,
$weeks = 0,
$days = 0,
$hours = 0,
$minutes = 0,
$seconds = 0,
$microseconds = 0
): self {
return $this->add("
$years years $months months $weeks weeks $days days
$hours hours $minutes minutes $seconds seconds $microseconds microseconds
");
}
/**
* Add given parameters to the current interval.
*
* @param int $years
* @param int $months
* @param int|float $weeks
* @param int|float $days
* @param int|float $hours
* @param int|float $minutes
* @param int|float $seconds
* @param int|float $microseconds
*
* @return $this
*/
public function minus(
$years = 0,
$months = 0,
$weeks = 0,
$days = 0,
$hours = 0,
$minutes = 0,
$seconds = 0,
$microseconds = 0
): self {
return $this->sub("
$years years $months months $weeks weeks $days days
$hours hours $minutes minutes $seconds seconds $microseconds microseconds
");
}
/**
* Multiply current instance given number of times. times() is naive, it multiplies each unit
* (so day can be greater than 31, hour can be greater than 23, etc.) and the result is rounded

View File

@@ -37,7 +37,7 @@ use RuntimeException;
/**
* Substitution of DatePeriod with some modifications and many more features.
*
* @property-read int $recurrences number of recurrences (if end not set).
* @property-read int|float $recurrences number of recurrences (if end not set).
* @property-read bool $include_start_date rather the start date is included in the iteration.
* @property-read bool $include_end_date rather the end date is included in the iteration (if recurrences not set).
* @property-read CarbonInterface $start Period start date.
@@ -212,6 +212,13 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
*/
public const NEXT_MAX_ATTEMPTS = 1000;
/**
* Number of maximum attempts before giving up on finding end date.
*
* @var int
*/
public const END_MAX_ATTEMPTS = 10000;
/**
* The registered macros.
*
@@ -681,6 +688,56 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
return clone $this;
}
/**
* Get the getter for a property allowing both `DatePeriod` snakeCase and camelCase names.
*
* @param string $name
*
* @return callable|null
*/
protected function getGetter(string $name)
{
switch (strtolower(preg_replace('/[A-Z]/', '_$0', $name))) {
case 'start':
case 'start_date':
return [$this, 'getStartDate'];
case 'end':
case 'end_date':
return [$this, 'getEndDate'];
case 'interval':
case 'date_interval':
return [$this, 'getDateInterval'];
case 'recurrences':
return [$this, 'getRecurrences'];
case 'include_start_date':
return [$this, 'isStartIncluded'];
case 'include_end_date':
return [$this, 'isEndIncluded'];
case 'current':
return [$this, 'current'];
default:
return null;
}
}
/**
* Get a property allowing both `DatePeriod` snakeCase and camelCase names.
*
* @param string $name
*
* @return bool|CarbonInterface|CarbonInterval|int|null
*/
public function get(string $name)
{
$getter = $this->getGetter($name);
if ($getter) {
return $getter();
}
throw new UnknownGetterException($name);
}
/**
* Get a property allowing both `DatePeriod` snakeCase and camelCase names.
*
@@ -690,27 +747,7 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
*/
public function __get(string $name)
{
switch (strtolower(preg_replace('/[A-Z]/', '_$0', $name))) {
case 'start':
case 'start_date':
return $this->getStartDate();
case 'end':
case 'end_date':
return $this->getEndDate();
case 'interval':
case 'date_interval':
return $this->getDateInterval();
case 'recurrences':
return $this->getRecurrences();
case 'include_start_date':
return $this->isStartIncluded();
case 'include_end_date':
return $this->isEndIncluded();
case 'current':
return $this->current();
default:
throw new UnknownGetterException($name);
}
return $this->get($name);
}
/**
@@ -722,13 +759,7 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
*/
public function __isset(string $name): bool
{
try {
$this->__get($name);
} catch (UnknownGetterException | ReflectionException $e) {
return false;
}
return true;
return $this->getGetter($name) !== null;
}
/**
@@ -957,7 +988,7 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
/**
* Get number of recurrences.
*
* @return int|null
* @return int|float|null
*/
public function getRecurrences()
{
@@ -1181,9 +1212,9 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
/**
* Add a recurrences filter (set maximum number of recurrences).
*
* @param int|null $recurrences
* @param int|float|null $recurrences
*
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*
* @return $this
*/
@@ -1197,7 +1228,7 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
return $this->removeFilter(static::RECURRENCES_FILTER);
}
$this->recurrences = (int) $recurrences;
$this->recurrences = $recurrences === INF ? INF : (int) $recurrences;
if (!$this->hasFilter(static::RECURRENCES_FILTER)) {
return $this->addFilter(static::RECURRENCES_FILTER);
@@ -1684,9 +1715,11 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
return $end;
}
$dates = iterator_to_array($this);
if ($this->dateInterval->isEmpty()) {
return $this->getStartDate($rounding);
}
$date = end($dates);
$date = $this->getEndFromRecurrences() ?? $this->iterateUntilEnd();
if ($date && $rounding) {
$date = $date->copy()->round($this->getDateInterval(), $rounding);
@@ -1695,6 +1728,56 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
return $date;
}
/**
* @return CarbonInterface|null
*/
private function getEndFromRecurrences()
{
if ($this->recurrences === null) {
throw new UnreachableException(
"Could not calculate period end without either explicit end or recurrences.\n".
"If you're looking for a forever-period, use ->setRecurrences(INF)."
);
}
if ($this->recurrences === INF) {
$start = $this->getStartDate();
return $start < $start->copy()->add($this->getDateInterval())
? CarbonImmutable::endOfTime()
: CarbonImmutable::startOfTime();
}
if ($this->filters === [[static::RECURRENCES_FILTER, null]]) {
return $this->getStartDate()->copy()->add(
$this->getDateInterval()->times(
$this->recurrences - ($this->isStartExcluded() ? 0 : 1)
)
);
}
return null;
}
/**
* @return CarbonInterface|null
*/
private function iterateUntilEnd()
{
$attempts = 0;
$date = null;
foreach ($this as $date) {
if (++$attempts > static::END_MAX_ATTEMPTS) {
throw new UnreachableException(
'Could not calculate period end after iterating '.static::END_MAX_ATTEMPTS.' times.'
);
}
}
return $date;
}
/**
* Returns true if the current period overlaps the given one (if 1 parameter passed)
* or the period between 2 dates (if 2 parameters passed).
@@ -1712,7 +1795,15 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
$range = static::create($range);
}
return $this->calculateEnd() > $range->getStartDate() && $range->calculateEnd() > $this->getStartDate();
$thisDates = [$this->getStartDate(), $this->calculateEnd()];
sort($thisDates);
[$start, $end] = $thisDates;
$rangeDates = [$range->getStartDate(), $range->calculateEnd()];
sort($rangeDates);
[$rangeStart, $rangeEnd] = $rangeDates;
return $end > $rangeStart && $rangeEnd > $start;
}
/**

View File

@@ -31,22 +31,23 @@
* - João Magalhães
* - Ingmar
* - Illimar Tambek
* - Mihkel
*/
return [
'year' => ':count aasta|:count aastat',
'y' => ':count aasta|:count aastat',
'y' => ':count a',
'month' => ':count kuu|:count kuud',
'm' => ':count kuu|:count kuud',
'm' => ':count k',
'week' => ':count nädal|:count nädalat',
'w' => ':count nädal|:count nädalat',
'w' => ':count näd',
'day' => ':count päev|:count päeva',
'd' => ':count päev|:count päeva',
'd' => ':count p',
'hour' => ':count tund|:count tundi',
'h' => ':count tund|:count tundi',
'h' => ':count t',
'minute' => ':count minut|:count minutit',
'min' => ':count minut|:count minutit',
'min' => ':count min',
'second' => ':count sekund|:count sekundit',
's' => ':count sekund|:count sekundit',
's' => ':count s',
'ago' => ':time tagasi',
'from_now' => ':time pärast',
'after' => ':time pärast',

View File

@@ -24,7 +24,7 @@
* - Serhan Apaydın
* - JD Isaacks
* - tomhorvat
* - Stjepan
* - Stjepan Majdak
* - Vanja Retkovac (vr00)
*/
return [
@@ -59,10 +59,10 @@ return [
'formats' => [
'LT' => 'H:mm',
'LTS' => 'H:mm:ss',
'L' => 'DD.MM.YYYY',
'LL' => 'D. MMMM YYYY',
'LLL' => 'D. MMMM YYYY H:mm',
'LLLL' => 'dddd, D. MMMM YYYY H:mm',
'L' => 'D. M. YYYY.',
'LL' => 'D. MMMM YYYY.',
'LLL' => 'D. MMMM YYYY. H:mm',
'LLLL' => 'dddd, D. MMMM YYYY. H:mm',
],
'calendar' => [
'sameDay' => '[danas u] LT',

View File

@@ -1,5 +1,7 @@
<?php
use Carbon\CarbonInterface;
/**
* This file is part of the Carbon package.
*
@@ -31,36 +33,69 @@
* - zakse
* - Janis Eglitis (janiseglitis)
* - Guntars
* - Juris Sudmalis
*/
return [
'year' => '0 gadiem|:count gads|:count gadiem',
'y' => '0 gadiem|:count gads|:count gadiem',
'a_year' => '{1}gads|0 gadiem|:count gads|:count gadiem',
'month' => '0 mēnešiem|:count mēneša|:count mēnešiem',
'm' => ':count mēn.',
'a_month' => '{1}mēneša|0 mēnešiem|:count mēneša|:count mēnešiem',
'week' => '0 nedēļām|:count nedēļas|:count nedēļām',
'w' => ':count ned.',
'a_week' => '{1}nedēļas|0 nedēļām|:count nedēļas|:count nedēļām',
'day' => '0 dienām|:count dienas|:count dienām',
'd' => '0 dienām|:count dienas|:count dienām',
'a_day' => '{1}dienas|0 dienām|:count dienas|:count dienām',
'hour' => '0 stundām|:count stundas|:count stundām',
'h' => ':count st.',
'a_hour' => '{1}stundas|0 stundām|:count stundas|:count stundām',
'minute' => '0 minūtēm|:count minūtes|:count minūtēm',
'min' => ':count min.',
'a_minute' => '{1}minūtes|0 minūtēm|:count minūtes|:count minūtēm',
'second' => '0 sekundēm|:count sekundes|:count sekundēm',
's' => ':count sek.',
'a_second' => '{1}dažas sekundes|0 sekundēm|:count sekundes|:count sekundēm',
$daysOfWeek = ['svētdiena', 'pirmdiena', 'otrdiena', 'trešdiena', 'ceturtdiena', 'piektdiena', 'sestdiena'];
$daysOfWeekLocativum = ['svētdien', 'pirmdien', 'otrdien', 'trešdien', 'ceturtdien', 'piektdien', 'sestdien'];
'ago' => 'pirms :time',
'from_now' => 'pēc :time',
$transformDiff = function ($input) {
return strtr($input, [
// Nominative => "pirms/pēc" Dative
'gads' => 'gada',
'gadi' => 'gadiem',
'gadu' => 'gadiem',
'mēnesis' => 'mēneša',
'mēneši' => 'mēnešiem',
'mēnešu' => 'mēnešiem',
'nedēļa' => 'nedēļas',
'nedēļas' => 'nedēļām',
'nedēļu' => 'nedēļām',
'diena' => 'dienas',
'dienas' => 'dienām',
'dienu' => 'dienām',
'stunda' => 'stundas',
'stundas' => 'stundām',
'stundu' => 'stundām',
'minūte' => 'minūtes',
'minūtes' => 'minūtēm',
'minūšu' => 'minūtēm',
'sekunde' => 'sekundes',
'sekundes' => 'sekundēm',
'sekunžu' => 'sekundēm',
]);
};
return [
'ago' => function ($time) use ($transformDiff) {
return 'pirms '.$transformDiff($time);
},
'from_now' => function ($time) use ($transformDiff) {
return 'pēc '.$transformDiff($time);
},
'year' => '0 gadu|:count gads|:count gadi',
'y' => ':count g.',
'a_year' => '{1}gads|0 gadu|:count gads|:count gadi',
'month' => '0 mēnešu|:count mēnesis|:count mēneši',
'm' => ':count mēn.',
'a_month' => '{1}mēnesis|0 mēnešu|:count mēnesis|:count mēneši',
'week' => '0 nedēļu|:count nedēļa|:count nedēļas',
'w' => ':count ned.',
'a_week' => '{1}nedēļa|0 nedēļu|:count nedēļa|:count nedēļas',
'day' => '0 dienu|:count diena|:count dienas',
'd' => ':count d.',
'a_day' => '{1}diena|0 dienu|:count diena|:count dienas',
'hour' => '0 stundu|:count stunda|:count stundas',
'h' => ':count st.',
'a_hour' => '{1}stunda|0 stundu|:count stunda|:count stundas',
'minute' => '0 minūšu|:count minūte|:count minūtes',
'min' => ':count min.',
'a_minute' => '{1}minūte|0 minūšu|:count minūte|:count minūtes',
'second' => '0 sekunžu|:count sekunde|:count sekundes',
's' => ':count sek.',
'a_second' => '{1}sekunde|0 sekunžu|:count sekunde|:count sekundes',
'after' => ':time vēlāk',
'before' => ':time pirms',
'year_after' => '0 gadus|:count gadu|:count gadus',
'a_year_after' => '{1}gadu|0 gadus|:count gadu|:count gadus',
'month_after' => '0 mēnešus|:count mēnesi|:count mēnešus',
@@ -76,6 +111,7 @@ return [
'second_after' => '0 sekundes|:count sekundi|:count sekundes',
'a_second_after' => '{1}sekundi|0 sekundes|:count sekundi|:count sekundes',
'before' => ':time agrāk',
'year_before' => '0 gadus|:count gadu|:count gadus',
'a_year_before' => '{1}gadu|0 gadus|:count gadu|:count gadus',
'month_before' => '0 mēnešus|:count mēnesi|:count mēnešus',
@@ -94,9 +130,14 @@ return [
'first_day_of_week' => 1,
'day_of_first_week_of_year' => 4,
'list' => [', ', ' un '],
'diff_now' => 'tagad',
'diff_today' => 'šodien',
'diff_yesterday' => 'vakar',
'diff_before_yesterday' => 'aizvakar',
'diff_tomorrow' => 'rīt',
'diff_after_tomorrow' => 'parīt',
'formats' => [
'LT' => 'HH:mm',
'LTS' => 'HH:mm:ss',
@@ -105,7 +146,25 @@ return [
'LLL' => 'DD.MM.YYYY., HH:mm',
'LLLL' => 'YYYY. [gada] D. MMMM, HH:mm',
],
'weekdays' => ['svētdiena', 'pirmdiena', 'otrdiena', 'trešdiena', 'ceturtdiena', 'piektdiena', 'sestdiena'],
'calendar' => [
'sameDay' => '[šodien] [plkst.] LT',
'nextDay' => '[rīt] [plkst.] LT',
'nextWeek' => function (CarbonInterface $current, CarbonInterface $other) use ($daysOfWeekLocativum) {
if ($current->week !== $other->week) {
return '[nākošo] ['.$daysOfWeekLocativum[$current->dayOfWeek].'] [plkst.] LT';
}
return '['.$daysOfWeekLocativum[$current->dayOfWeek].'] [plkst.] LT';
},
'lastDay' => '[vakar] [plkst.] LT',
'lastWeek' => function (CarbonInterface $current) use ($daysOfWeekLocativum) {
return '[pagājušo] ['.$daysOfWeekLocativum[$current->dayOfWeek].'] [plkst.] LT';
},
'sameElse' => 'L',
],
'weekdays' => $daysOfWeek,
'weekdays_short' => ['Sv.', 'P.', 'O.', 'T.', 'C.', 'Pk.', 'S.'],
'weekdays_min' => ['Sv.', 'P.', 'O.', 'T.', 'C.', 'Pk.', 'S.'],
'months' => ['janvārī', 'februārī', 'martā', 'aprīlī', 'maijā', 'jūnijā', 'jūlijā', 'augustā', 'septembrī', 'oktobrī', 'novembrī', 'decembrī'],

View File

@@ -75,11 +75,11 @@ return [
'sameElse' => 'L',
],
'meridiem' => function ($hour) {
if ($hour < 11) {
if ($hour < 12) {
return 'pagi';
}
if ($hour < 15) {
return 'tengahari';
return 'tengah hari';
}
if ($hour < 19) {
return 'petang';

View File

@@ -79,11 +79,11 @@ return [
},
'diff_now' => 'только что',
'diff_today' => 'Сегодня,',
'diff_today_regexp' => 'Сегодня,(?:\\s+в)?',
'diff_today_regexp' => 'Сегодня,?(?:\\s+в)?',
'diff_yesterday' => 'вчера',
'diff_yesterday_regexp' => 'Вчера,(?:\\s+в)?',
'diff_yesterday_regexp' => 'Вчера,?(?:\\s+в)?',
'diff_tomorrow' => 'завтра',
'diff_tomorrow_regexp' => 'Завтра,(?:\\s+в)?',
'diff_tomorrow_regexp' => 'Завтра,?(?:\\s+в)?',
'diff_before_yesterday' => 'позавчера',
'diff_after_tomorrow' => 'послезавтра',
'formats' => [

View File

@@ -71,35 +71,35 @@ return [
'a_minute' => '{1}хвилина|:count хвилина|:count хвилини|:count хвилин',
'second' => ':count секунда|:count секунди|:count секунд',
's' => ':countсек',
'a_second' => '{1}кілька секунд|:count секунда|:count секунди|:count секунд',
'a_second' => '{1}декілька секунд|:count секунда|:count секунди|:count секунд',
'hour_ago' => ':count годину|:count години|:count годин',
'a_hour_ago' => '{1}годину|:count годину|:count години|:count годин',
'minute_ago' => ':count хвилину|:count хвилини|:count хвилин',
'a_minute_ago' => '{1}хвилину|:count хвилину|:count хвилини|:count хвилин',
'second_ago' => ':count секунду|:count секунди|:count секунд',
'a_second_ago' => '{1}кілька секунд|:count секунду|:count секунди|:count секунд',
'a_second_ago' => '{1}декілька секунд|:count секунду|:count секунди|:count секунд',
'hour_from_now' => ':count годину|:count години|:count годин',
'a_hour_from_now' => '{1}годину|:count годину|:count години|:count годин',
'minute_from_now' => ':count хвилину|:count хвилини|:count хвилин',
'a_minute_from_now' => '{1}хвилину|:count хвилину|:count хвилини|:count хвилин',
'second_from_now' => ':count секунду|:count секунди|:count секунд',
'a_second_from_now' => '{1}кілька секунд|:count секунду|:count секунди|:count секунд',
'a_second_from_now' => '{1}декілька секунд|:count секунду|:count секунди|:count секунд',
'hour_after' => ':count годину|:count години|:count годин',
'a_hour_after' => '{1}годину|:count годину|:count години|:count годин',
'minute_after' => ':count хвилину|:count хвилини|:count хвилин',
'a_minute_after' => '{1}хвилину|:count хвилину|:count хвилини|:count хвилин',
'second_after' => ':count секунду|:count секунди|:count секунд',
'a_second_after' => '{1}кілька секунд|:count секунду|:count секунди|:count секунд',
'a_second_after' => '{1}декілька секунд|:count секунду|:count секунди|:count секунд',
'hour_before' => ':count годину|:count години|:count годин',
'a_hour_before' => '{1}годину|:count годину|:count години|:count годин',
'minute_before' => ':count хвилину|:count хвилини|:count хвилин',
'a_minute_before' => '{1}хвилину|:count хвилину|:count хвилини|:count хвилин',
'second_before' => ':count секунду|:count секунди|:count секунд',
'a_second_before' => '{1}кілька секунд|:count секунду|:count секунди|:count секунд',
'a_second_before' => '{1}декілька секунд|:count секунду|:count секунди|:count секунд',
'ago' => ':time тому',
'from_now' => 'за :time',

View File

@@ -31,6 +31,12 @@ use InvalidArgumentException;
*/
trait Comparison
{
/** @var bool */
protected $endOfTime = false;
/** @var bool */
protected $startOfTime = false;
/**
* Determines if the instance is equal to another
*
@@ -1040,4 +1046,24 @@ trait Comparison
return (bool) @preg_match('/^'.$regex.'$/', $date);
}
/**
* Returns true if the date was created using CarbonImmutable::startOfTime()
*
* @return bool
*/
public function isStartOfTime(): bool
{
return $this->startOfTime ?? false;
}
/**
* Returns true if the date was created using CarbonImmutable::endOfTime()
*
* @return bool
*/
public function isEndOfTime(): bool
{
return $this->endOfTime ?? false;
}
}

View File

@@ -48,8 +48,8 @@ trait Creator
* Please see the testing aids section (specifically static::setTestNow())
* for more on the possibility of this constructor returning a test instance.
*
* @param string|null $time
* @param DateTimeZone|string|null $tz
* @param DateTimeInterface|string|null $time
* @param DateTimeZone|string|null $tz
*
* @throws InvalidFormatException
*/
@@ -873,8 +873,7 @@ trait Creator
if (\is_string($var)) {
$var = trim($var);
if (\is_string($var) &&
!preg_match('/^P[0-9T]/', $var) &&
if (!preg_match('/^P[0-9T]/', $var) &&
!preg_match('/^R[0-9]/', $var) &&
preg_match('/[a-z0-9]/i', $var)
) {

View File

@@ -1374,17 +1374,17 @@ trait Date
/**
* Returns the minutes offset to UTC if no arguments passed, else set the timezone with given minutes shift passed.
*
* @param int|null $offset
* @param int|null $minuteOffset
*
* @return int|static
*/
public function utcOffset(int $offset = null)
public function utcOffset(int $minuteOffset = null)
{
if (\func_num_args() < 1) {
return $this->offsetMinutes;
}
return $this->setTimezone(static::safeCreateDateTimeZone($offset / static::MINUTES_PER_HOUR));
return $this->setTimezone(CarbonTimeZone::createFromMinuteOffset($minuteOffset));
}
/**

View File

@@ -638,9 +638,11 @@ trait Difference
*/
public function floatDiffInRealDays($date = null, $absolute = true)
{
$hoursDiff = $this->floatDiffInRealHours($date, $absolute);
$date = $this->resolveCarbon($date)->utc();
$utc = $this->copy()->utc();
$hoursDiff = $utc->floatDiffInRealHours($date, $absolute);
return ($hoursDiff < 0 ? -1 : 1) * $this->diffInDays($date) + fmod($hoursDiff, static::HOURS_PER_DAY) / static::HOURS_PER_DAY;
return ($hoursDiff < 0 ? -1 : 1) * $utc->diffInDays($date) + fmod($hoursDiff, static::HOURS_PER_DAY) / static::HOURS_PER_DAY;
}
/**
@@ -1089,7 +1091,10 @@ trait Difference
}
/**
* Returns either the close date "Friday 15h30", or a calendar date "10/09/2017" is farthest than 7 days from now.
* Returns either day of week + time (e.g. "Last Friday at 3:30 PM") if reference time is within 7 days,
* or a calendar date (e.g. "10/29/2017") otherwise.
*
* Language, date and time formats will change according to the current locale.
*
* @param Carbon|\DateTimeInterface|string|null $referenceTime
* @param array $formats

View File

@@ -396,11 +396,11 @@ trait Localization
);
}
return substr(preg_replace_callback('/(?<=[\d\s+.\/,_-])('.implode('|', $fromTranslations).')(?=[\d\s+.\/,_-])/i', function ($match) use ($fromTranslations, $toTranslations) {
return substr(preg_replace_callback('/(?<=[\d\s+.\/,_-])('.implode('|', $fromTranslations).')(?=[\d\s+.\/,_-])/iu', function ($match) use ($fromTranslations, $toTranslations) {
[$chunk] = $match;
foreach ($fromTranslations as $index => $word) {
if (preg_match("/^$word\$/i", $chunk)) {
if (preg_match("/^$word\$/iu", $chunk)) {
return $toTranslations[$index] ?? '';
}
}

View File

@@ -107,11 +107,15 @@ trait Mixin
$context = isset($this) ? $this->cast($className) : new $className();
try {
$closure = $closureBase->bindTo($context);
} catch (Throwable $throwable) {
$closure = $closureBase;
// @ is required to handle error if not converted into exceptions
$closure = @$closureBase->bindTo($context);
} catch (Throwable $throwable) { // @codeCoverageIgnore
$closure = $closureBase; // @codeCoverageIgnore
}
// in case of errors not converted into exceptions
$closure = $closure ?? $closureBase;
return $closure(...\func_get_args());
});
}

View File

@@ -61,7 +61,7 @@ trait Options
/**
* Format regex patterns.
*
* @var array
* @var array<string, string>
*/
protected static $regexFormats = [
'd' => '(3[01]|[12][0-9]|0[1-9])',
@@ -72,7 +72,7 @@ trait Options
'S' => '(st|nd|rd|th)',
'w' => '([0-6])',
'z' => '(36[0-5]|3[0-5][0-9]|[12][0-9]{2}|[1-9]?[0-9])',
'W' => '(5[012]|[1-4][0-9]|[1-9])',
'W' => '(5[012]|[1-4][0-9]|0?[1-9])',
'F' => '([a-zA-Z]{2,})',
'm' => '(1[012]|0[1-9])',
'M' => '([a-zA-Z]{3})',
@@ -97,6 +97,7 @@ trait Options
'I' => '(0|1)',
'O' => '([+-](1[012]|0[0-9])[0134][05])',
'P' => '([+-](1[012]|0[0-9]):[0134][05])',
'p' => '(Z|[+-](1[012]|0[0-9]):[0134][05])',
'T' => '([a-zA-Z]{1,5})',
'Z' => '(-?[1-5]?[0-9]{1,4})',
'U' => '([0-9]*)',
@@ -412,8 +413,10 @@ trait Options
'tzName' => 'timezone',
'localFormatFunction' => 'formatFunction',
];
foreach ($map as $property => $key) {
$value = $this->$property ?? null;
if ($value !== null) {
$settings[$key] = $value;
}

View File

@@ -56,6 +56,7 @@ trait Rounding
'microsecond' => [0, 999999],
]);
$factor = 1;
$initialMonth = $this->month;
if ($normalizedUnit === 'week') {
$normalizedUnit = 'day';
@@ -106,16 +107,19 @@ trait Rounding
}
[$value, $minimum] = $arguments;
$normalizedValue = floor($function(($value - $minimum) / $precision) * $precision + $minimum);
/** @var CarbonInterface $result */
$result = $this->$normalizedUnit(
floor($function(($value - $minimum) / $precision) * $precision + $minimum)
);
$result = $this->$normalizedUnit($normalizedValue);
foreach ($changes as $unit => $value) {
$result = $result->$unit($value);
}
return $result;
return $normalizedUnit === 'month' && $precision <= 1 && abs($result->month - $initialMonth) === 2
// Re-run the change in case an overflow occurred
? $result->$normalizedUnit($normalizedValue)
: $result;
}
/**

View File

@@ -313,7 +313,7 @@ class Translator extends Translation\Translator
*/
public function setLocale($locale)
{
$locale = preg_replace_callback('/[-_]([a-z]{2,})/', function ($matches) {
$locale = preg_replace_callback('/[-_]([a-z]{2,}|[0-9]{2,})/', function ($matches) {
// _2-letters or YUE is a region, _3+-letters is a variant
$upper = strtoupper($matches[1]);