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

Breadcrumb

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

function ShowCommand::getRelativeTime

2 calls to ShowCommand::getRelativeTime()
ShowCommand::execute in vendor/composer/composer/src/Composer/Command/ShowCommand.php
Executes the current command.
ShowCommand::printMeta in vendor/composer/composer/src/Composer/Command/ShowCommand.php
Prints package metadata.

File

vendor/composer/composer/src/Composer/Command/ShowCommand.php, line 1533

Class

ShowCommand
@author Robert Schönthal <seroscho@googlemail.com> @author Jordi Boggiano <j.boggiano@seld.be> @author Jérémy Romey <jeremyFreeAgent> @author Mihai Plasoianu <mihai@plasoianu.de>

Namespace

Composer\Command

Code

private function getRelativeTime(\DateTimeInterface $releaseDate) : string {
    if ($releaseDate->format('Ymd') === date('Ymd')) {
        return 'today';
    }
    $diff = $releaseDate->diff(new \DateTimeImmutable());
    if ($diff->days < 7) {
        return 'this week';
    }
    if ($diff->days < 14) {
        return 'last week';
    }
    if ($diff->m < 1 && $diff->days < 31) {
        return floor($diff->days / 7) . ' weeks ago';
    }
    if ($diff->y < 1) {
        return $diff->m . ' month' . ($diff->m > 1 ? 's' : '') . ' ago';
    }
    return $diff->y . ' year' . ($diff->y > 1 ? 's' : '') . ' ago';
}

API Navigation

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