Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DateCaster.php

function DateCaster::castPeriod

File

vendor/symfony/var-dumper/Caster/DateCaster.php, line 90

Class

DateCaster
Casts DateTimeInterface related classes to array representation.

Namespace

Symfony\Component\VarDumper\Caster

Code

public static function castPeriod(\DatePeriod $p, array $a, Stub $stub, bool $isNested, int $filter) : array {
    $dates = [];
    foreach (clone $p as $i => $d) {
        if (self::PERIOD_LIMIT === $i) {
            $now = new \DateTimeImmutable('now', new \DateTimeZone('UTC'));
            $dates[] = \sprintf('%s more', ($end = $p->getEndDate()) ? 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;
        }
        $dates[] = \sprintf('%s) %s', $i + 1, self::formatDateTime($d));
    }
    $period = \sprintf('every %s, from %s%s %s', self::formatInterval($p->getDateInterval()), $p->include_start_date ? '[' : ']', self::formatDateTime($p->getStartDate()), ($end = $p->getEndDate()) ? 'to ' . self::formatDateTime($end) . ($p->include_end_date ? ']' : '[') : 'recurring ' . $p->recurrences . ' time/s');
    $p = [
        Caster::PREFIX_VIRTUAL . 'period' => new ConstStub($period, implode("\n", $dates)),
    ];
    return $filter & Caster::EXCLUDE_VERBOSE ? $p : $p + $a;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal