updated-packages
This commit is contained in:
39
vendor/symfony/var-dumper/Caster/DateCaster.php
vendored
39
vendor/symfony/var-dumper/Caster/DateCaster.php
vendored
@@ -17,6 +17,8 @@ use Symfony\Component\VarDumper\Cloner\Stub;
|
||||
* Casts DateTimeInterface related classes to array representation.
|
||||
*
|
||||
* @author Dany Maillard <danymaillard93b@gmail.com>
|
||||
*
|
||||
* @final since Symfony 4.4
|
||||
*/
|
||||
class DateCaster
|
||||
{
|
||||
@@ -33,7 +35,11 @@ class DateCaster
|
||||
.($location ? ($d->format('I') ? "\nDST On" : "\nDST Off") : '')
|
||||
;
|
||||
|
||||
$a = array();
|
||||
unset(
|
||||
$a[Caster::PREFIX_DYNAMIC.'date'],
|
||||
$a[Caster::PREFIX_DYNAMIC.'timezone'],
|
||||
$a[Caster::PREFIX_DYNAMIC.'timezone_type']
|
||||
);
|
||||
$a[$prefix.'date'] = new ConstStub(self::formatDateTime($d, $location ? ' e (P)' : ' P'), $title);
|
||||
|
||||
$stub->class .= $d->format(' @U');
|
||||
@@ -43,21 +49,22 @@ class DateCaster
|
||||
|
||||
public static function castInterval(\DateInterval $interval, array $a, Stub $stub, $isNested, $filter)
|
||||
{
|
||||
$now = new \DateTimeImmutable();
|
||||
$now = new \DateTimeImmutable('@0', new \DateTimeZone('UTC'));
|
||||
$numberOfSeconds = $now->add($interval)->getTimestamp() - $now->getTimestamp();
|
||||
$title = number_format($numberOfSeconds, 0, '.', ' ').'s';
|
||||
|
||||
$i = array(Caster::PREFIX_VIRTUAL.'interval' => new ConstStub(self::formatInterval($interval), $title));
|
||||
$i = [Caster::PREFIX_VIRTUAL.'interval' => new ConstStub(self::formatInterval($interval), $title)];
|
||||
|
||||
return $filter & Caster::EXCLUDE_VERBOSE ? $i : $i + $a;
|
||||
}
|
||||
|
||||
private static function formatInterval(\DateInterval $i)
|
||||
private static function formatInterval(\DateInterval $i): string
|
||||
{
|
||||
$format = '%R ';
|
||||
|
||||
if (0 === $i->y && 0 === $i->m && ($i->h >= 24 || $i->i >= 60 || $i->s >= 60)) {
|
||||
$i = date_diff($d = new \DateTime(), date_add(clone $d, $i)); // recalculate carry over points
|
||||
$d = new \DateTimeImmutable('@0', new \DateTimeZone('UTC'));
|
||||
$i = $d->diff($d->add($i)); // recalculate carry over points
|
||||
$format .= 0 < $i->days ? '%ad ' : '';
|
||||
} else {
|
||||
$format .= ($i->y ? '%yy ' : '').($i->m ? '%mm ' : '').($i->d ? '%dd ' : '');
|
||||
@@ -75,20 +82,20 @@ class DateCaster
|
||||
$formatted = (new \DateTime('now', $timeZone))->format($location ? 'e (P)' : 'P');
|
||||
$title = $location && \extension_loaded('intl') ? \Locale::getDisplayRegion('-'.$location['country_code']) : '';
|
||||
|
||||
$z = array(Caster::PREFIX_VIRTUAL.'timezone' => new ConstStub($formatted, $title));
|
||||
$z = [Caster::PREFIX_VIRTUAL.'timezone' => new ConstStub($formatted, $title)];
|
||||
|
||||
return $filter & Caster::EXCLUDE_VERBOSE ? $z : $z + $a;
|
||||
}
|
||||
|
||||
public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, $isNested, $filter)
|
||||
{
|
||||
$dates = array();
|
||||
if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/bug.php?id=74639
|
||||
$dates = [];
|
||||
if (\PHP_VERSION_ID >= 70107) { // see https://bugs.php.net/74639
|
||||
foreach (clone $p as $i => $d) {
|
||||
if (self::PERIOD_LIMIT === $i) {
|
||||
$now = new \DateTimeImmutable();
|
||||
$now = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
|
||||
$dates[] = sprintf('%s more', ($end = $p->getEndDate())
|
||||
? ceil(($end->format('U.u') - $d->format('U.u')) / ($now->add($p->getDateInterval())->format('U.u') - $now->format('U.u')))
|
||||
? ceil(($end->format('U.u') - $d->format('U.u')) / ((int) $now->add($p->getDateInterval())->format('U.u') - (int) $now->format('U.u')))
|
||||
: $p->recurrences - $i
|
||||
);
|
||||
break;
|
||||
@@ -98,24 +105,24 @@ class DateCaster
|
||||
}
|
||||
|
||||
$period = sprintf(
|
||||
'every %s, from %s (%s) %s',
|
||||
'every %s, from %s%s %s',
|
||||
self::formatInterval($p->getDateInterval()),
|
||||
$p->include_start_date ? '[' : ']',
|
||||
self::formatDateTime($p->getStartDate()),
|
||||
$p->include_start_date ? 'included' : 'excluded',
|
||||
($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end) : 'recurring '.$p->recurrences.' time/s'
|
||||
($end = $p->getEndDate()) ? 'to '.self::formatDateTime($end).(\PHP_VERSION_ID >= 80200 && $p->include_end_date ? ']' : '[') : 'recurring '.$p->recurrences.' time/s'
|
||||
);
|
||||
|
||||
$p = array(Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates)));
|
||||
$p = [Caster::PREFIX_VIRTUAL.'period' => new ConstStub($period, implode("\n", $dates))];
|
||||
|
||||
return $filter & Caster::EXCLUDE_VERBOSE ? $p : $p + $a;
|
||||
}
|
||||
|
||||
private static function formatDateTime(\DateTimeInterface $d, $extra = '')
|
||||
private static function formatDateTime(\DateTimeInterface $d, string $extra = ''): string
|
||||
{
|
||||
return $d->format('Y-m-d H:i:'.self::formatSeconds($d->format('s'), $d->format('u')).$extra);
|
||||
}
|
||||
|
||||
private static function formatSeconds($s, $us)
|
||||
private static function formatSeconds(string $s, string $us): string
|
||||
{
|
||||
return sprintf('%02d.%s', $s, 0 === ($len = \strlen($t = rtrim($us, '0'))) ? '0' : ($len <= 3 ? str_pad($t, 3, '0') : $us));
|
||||
}
|
||||
|
Reference in New Issue
Block a user