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

Breadcrumb

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

function DateCaster::formatInterval

3 calls to DateCaster::formatInterval()
DateCaster::castDateTime in vendor/symfony/var-dumper/Caster/DateCaster.php
DateCaster::castInterval in vendor/symfony/var-dumper/Caster/DateCaster.php
DateCaster::castPeriod in vendor/symfony/var-dumper/Caster/DateCaster.php

File

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

Class

DateCaster
Casts DateTimeInterface related classes to array representation.

Namespace

Symfony\Component\VarDumper\Caster

Code

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)) {
        $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 ' : '');
    }
    $format .= $i->h || $i->i || $i->s || $i->f ? '%H:%I:' . self::formatSeconds($i->s, substr($i->f, 2)) : '';
    $format = '%R ' === $format ? '0s' : $format;
    return $i->format(rtrim($format));
}

API Navigation

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