[Web] Update libs

This commit is contained in:
andryyy
2021-05-23 13:20:53 +02:00
parent e6d5516c7f
commit 8779a1a873
48 changed files with 656 additions and 272 deletions

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
*/
@@ -2629,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.
*
@@ -2839,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.)

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.
*
@@ -981,7 +988,7 @@ class CarbonPeriod implements Iterator, Countable, JsonSerializable
/**
* Get number of recurrences.
*
* @return int|null
* @return int|float|null
*/
public function getRecurrences()
{
@@ -1205,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
*/
@@ -1221,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);
@@ -1708,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);
@@ -1719,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).
@@ -1736,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

@@ -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

@@ -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]*)',

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]);