package updates

This commit is contained in:
2018-12-19 23:27:43 -06:00
parent aa1da4d4fb
commit 1ffd21369f
1181 changed files with 51194 additions and 11046 deletions
+4 -1
View File
@@ -25,9 +25,12 @@
"symfony/translation": "~2.6 || ~3.0 || ~4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2",
"phpunit/phpunit": "^4.8.35 || ^5.7"
},
"suggest": {
"friendsofphp/php-cs-fixer": "Needed for the `composer phpcs` command. Allow to automatically fix code style.",
"phpstan/phpstan": "Needed for the `composer phpstan` command. Allow to detect potential errors."
},
"autoload": {
"psr-4": {
"": "src/"
+113 -12
View File
@@ -13,6 +13,7 @@ namespace Carbon;
use Carbon\Exceptions\InvalidDateException;
use Closure;
use DateInterval;
use DatePeriod;
use DateTime;
use DateTimeInterface;
@@ -195,7 +196,7 @@ class Carbon extends DateTime implements JsonSerializable
't' => '(2[89]|3[01])',
'L' => '(0|1)',
'o' => '([1-9][0-9]{0,4})',
'Y' => '([1-9][0-9]{0,4})',
'Y' => '([1-9]?[0-9]{4})',
'y' => '([0-9]{2})',
'a' => '(am|pm)',
'A' => '(AM|PM)',
@@ -217,8 +218,8 @@ class Carbon extends DateTime implements JsonSerializable
'U' => '([0-9]*)',
// The formats below are combinations of the above formats.
'c' => '(([1-9][0-9]{0,4})\-(1[012]|0[1-9])\-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[\+\-](1[012]|0[0-9]):([0134][05]))', // Y-m-dTH:i:sP
'r' => '(([a-zA-Z]{3}), ([123][0-9]|[1-9]) ([a-zA-Z]{3}) ([1-9][0-9]{0,4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [\+\-](1[012]|0[0-9])([0134][05]))', // D, j M Y H:i:s O
'c' => '(([1-9]?[0-9]{4})\-(1[012]|0[1-9])\-(3[01]|[12][0-9]|0[1-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])[\+\-](1[012]|0[0-9]):([0134][05]))', // Y-m-dTH:i:sP
'r' => '(([a-zA-Z]{3}), ([123][0-9]|[1-9]) ([a-zA-Z]{3}) ([1-9]?[0-9]{4}) (2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9]) [\+\-](1[012]|0[0-9])([0134][05]))', // D, j M Y H:i:s O
);
/**
@@ -2264,6 +2265,13 @@ class Carbon extends DateTime implements JsonSerializable
return $this->gt($date1) && $this->lt($date2);
}
protected function floatDiffInSeconds($date)
{
$date = $this->resolveCarbon($date);
return abs($this->diffInRealSeconds($date, false) + ($date->micro - $this->micro) / 1000000);
}
/**
* Get the closest date from the instance.
*
@@ -2274,7 +2282,7 @@ class Carbon extends DateTime implements JsonSerializable
*/
public function closest($date1, $date2)
{
return $this->diffInSeconds($date1) < $this->diffInSeconds($date2) ? $date1 : $date2;
return $this->floatDiffInSeconds($date1) < $this->floatDiffInSeconds($date2) ? $date1 : $date2;
}
/**
@@ -2287,7 +2295,7 @@ class Carbon extends DateTime implements JsonSerializable
*/
public function farthest($date1, $date2)
{
return $this->diffInSeconds($date1) > $this->diffInSeconds($date2) ? $date1 : $date2;
return $this->floatDiffInSeconds($date1) > $this->floatDiffInSeconds($date2) ? $date1 : $date2;
}
/**
@@ -3754,16 +3762,91 @@ class Carbon extends DateTime implements JsonSerializable
///////////////////////////////////////////////////////////////////
/**
* Get the difference as a CarbonInterval instance
*
* @param \Carbon\Carbon|\DateTimeInterface|string|null $date
* @param bool $absolute Get the absolute of the difference
* @param DateInterval $diff
* @param bool $absolute
* @param bool $trimMicroseconds
*
* @return CarbonInterval
*/
public function diffAsCarbonInterval($date = null, $absolute = true)
protected static function fixDiffInterval(DateInterval $diff, $absolute, $trimMicroseconds)
{
return CarbonInterval::instance($this->diff($this->resolveCarbon($date), $absolute));
$diff = CarbonInterval::instance($diff, $trimMicroseconds);
// @codeCoverageIgnoreStart
if (version_compare(PHP_VERSION, '7.1.0-dev', '<')) {
return $diff;
}
// Work-around for https://bugs.php.net/bug.php?id=77145
if ($diff->f > 0 && $diff->y === -1 && $diff->m === 11 && $diff->d >= 27 && $diff->h === 23 && $diff->i === 59 && $diff->s === 59) {
$diff->y = 0;
$diff->m = 0;
$diff->d = 0;
$diff->h = 0;
$diff->i = 0;
$diff->s = 0;
$diff->f = (1000000 - round($diff->f * 1000000)) / 1000000;
$diff->invert();
} elseif ($diff->f < 0) {
if ($diff->s !== 0 || $diff->i !== 0 || $diff->h !== 0 || $diff->d !== 0 || $diff->m !== 0 || $diff->y !== 0) {
$diff->f = (round($diff->f * 1000000) + 1000000) / 1000000;
$diff->s--;
if ($diff->s < 0) {
$diff->s += 60;
$diff->i--;
if ($diff->i < 0) {
$diff->i += 60;
$diff->h--;
if ($diff->h < 0) {
$diff->i += 24;
$diff->d--;
if ($diff->d < 0) {
$diff->d += 30;
$diff->m--;
if ($diff->m < 0) {
$diff->m += 12;
$diff->y--;
}
}
}
}
}
} else {
$diff->f *= -1;
$diff->invert();
}
}
// @codeCoverageIgnoreEnd
if ($absolute && $diff->invert) {
$diff->invert();
}
return $diff;
}
/**
* Get the difference as a CarbonInterval instance.
*
* Pass false as second argument to get a microseconds-precise interval. Else
* microseconds in the original interval will not be kept.
*
* @param \Carbon\Carbon|\DateTimeInterface|string|null $date
* @param bool $absolute Get the absolute of the difference
* @param bool $trimMicroseconds (true by default)
*
* @return CarbonInterval
*/
public function diffAsCarbonInterval($date = null, $absolute = true, $trimMicroseconds = true)
{
$from = $this;
$to = $this->resolveCarbon($date);
if ($trimMicroseconds) {
$from = $from->copy()->startOfSecond();
$to = $to->copy()->startOfSecond();
}
return static::fixDiffInterval($from->diff($to, $absolute), $absolute, $trimMicroseconds);
}
/**
@@ -3973,6 +4056,9 @@ class Carbon extends DateTime implements JsonSerializable
public function diffInSeconds($date = null, $absolute = true)
{
$diff = $this->diff($this->resolveCarbon($date));
if (!$diff->days && version_compare(PHP_VERSION, '5.4.0-dev', '>=')) {
$diff = static::fixDiffInterval($diff, $absolute, false);
}
$value = $diff->days * static::HOURS_PER_DAY * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE +
$diff->h * static::MINUTES_PER_HOUR * static::SECONDS_PER_MINUTE +
$diff->i * static::SECONDS_PER_MINUTE +
@@ -4651,7 +4737,22 @@ class Carbon extends DateTime implements JsonSerializable
*/
public function average($date = null)
{
return $this->addSeconds((int) ($this->diffInSeconds($this->resolveCarbon($date), false) / 2));
$date = $this->resolveCarbon($date);
$increment = $this->diffInRealSeconds($date, false) / 2;
$intIncrement = floor($increment);
$microIncrement = (int) (($date->micro - $this->micro) / 2 + 1000000 * ($increment - $intIncrement));
$micro = (int) ($this->micro + $microIncrement);
while ($micro >= 1000000) {
$micro -= 1000000;
$intIncrement++;
}
$this->addSeconds($intIncrement);
if (version_compare(PHP_VERSION, '7.1.8-dev', '>=')) {
$this->setTime($this->hour, $this->minute, $this->second, $micro);
}
return $this;
}
///////////////////////////////////////////////////////////////////
+33 -8
View File
@@ -490,14 +490,27 @@ class CarbonInterval extends DateInterval
* DateInterval objects created from DateTime::diff() as you can't externally
* set the $days field.
*
* Pass false as second argument to get a microseconds-precise interval. Else
* microseconds in the original interval will not be kept.
*
* @param DateInterval $di
* @param bool $trimMicroseconds (true by default)
*
* @return static
*/
public static function instance(DateInterval $di)
public static function instance(DateInterval $di, $trimMicroseconds = true)
{
$microseconds = $trimMicroseconds || version_compare(PHP_VERSION, '7.1.0-dev', '<') ? 0 : $di->f;
$instance = new static(static::getDateIntervalSpec($di));
if ($microseconds) {
$instance->f = $microseconds;
}
$instance->invert = $di->invert;
foreach (array('y', 'm', 'd', 'h', 'i', 's') as $unit) {
if ($di->$unit < 0) {
$instance->$unit *= -1;
}
}
return $instance;
}
@@ -911,7 +924,7 @@ class CarbonInterval extends DateInterval
*/
public function add(DateInterval $interval)
{
$sign = $interval->invert === 1 ? -1 : 1;
$sign = ($this->invert === 1) !== ($interval->invert === 1) ? -1 : 1;
if (static::wasCreatedFromDiff($interval)) {
$this->dayz += $interval->days * $sign;
@@ -924,6 +937,18 @@ class CarbonInterval extends DateInterval
$this->seconds += $interval->s * $sign;
}
if (($this->years || $this->months || $this->dayz || $this->hours || $this->minutes || $this->seconds) &&
$this->years <= 0 && $this->months <= 0 && $this->dayz <= 0 && $this->hours <= 0 && $this->minutes <= 0 && $this->seconds <= 0
) {
$this->years *= -1;
$this->months *= -1;
$this->dayz *= -1;
$this->hours *= -1;
$this->minutes *= -1;
$this->seconds *= -1;
$this->invert();
}
return $this;
}
@@ -961,15 +986,15 @@ class CarbonInterval extends DateInterval
public static function getDateIntervalSpec(DateInterval $interval)
{
$date = array_filter(array(
static::PERIOD_YEARS => $interval->y,
static::PERIOD_MONTHS => $interval->m,
static::PERIOD_DAYS => $interval->d,
static::PERIOD_YEARS => abs($interval->y),
static::PERIOD_MONTHS => abs($interval->m),
static::PERIOD_DAYS => abs($interval->d),
));
$time = array_filter(array(
static::PERIOD_HOURS => $interval->h,
static::PERIOD_MINUTES => $interval->i,
static::PERIOD_SECONDS => $interval->s,
static::PERIOD_HOURS => abs($interval->h),
static::PERIOD_MINUTES => abs($interval->i),
static::PERIOD_SECONDS => abs($interval->s),
));
$specString = static::PERIOD_PREFIX;