Chora::readableTime PHP Méthode

readableTime() public static méthode

Return a text description of how long its been since the file has been last modified.
public static readableTime ( integer $date, boolean $long = false ) : string
$date integer Number of seconds since epoch we wish to display.
$long boolean If true, display a more verbose date.
Résultat string The human-readable date.
    public static function readableTime($date, $long = false)
    {
        /* Initialize popular variables. */
        if (!isset(self::$rtcache)) {
            $desc = array(1 => array(_("second"), _("seconds")), 60 => array(_("minute"), _("minutes")), 3600 => array(_("hour"), _("hours")), 86400 => array(_("day"), _("days")), 604800 => array(_("week"), _("weeks")), 2628000 => array(_("month"), _("months")), 31536000 => array(_("year"), _("years")));
            self::$rtcache = array('breaks' => array_keys($desc), 'desc' => $desc, 'time' => time());
        }
        $cache = self::$rtcache;
        $i = count($cache['breaks']);
        $secs = $cache['time'] - $date;
        if ($secs < 2) {
            return _("very little time");
        }
        while (--$i && $i && $cache['breaks'][$i] * 2 > $secs) {
        }
        $break = $cache['breaks'][$i];
        $val = intval($secs / $break);
        $retval = $val . ' ' . ($val > 1 ? $cache['desc'][$break][1] : $cache['desc'][$break][0]);
        if ($long && $i > 0) {
            $rest = $secs % $break;
            $break = $cache['breaks'][--$i];
            $rest = (int) ($rest / $break);
            if ($rest > 0) {
                $retval .= ', ' . $rest . ' ' . ($rest > 1 ? $cache['desc'][$break][1] : $cache['desc'][$break][0]);
            }
        }
        return $retval;
    }

Usage Example

Exemple #1
0
    if (!isset($title)) {
        $title = _("Commits to:");
    }
}
try {
    $ps = $VC->getPatchset($ps_opts);
    $patchsets = $ps->getPatchsets();
} catch (Horde_Vcs_Exception $e) {
    Chora::fatal($e);
}
if (empty($patchsets)) {
    Chora::fatal(_("Commit Not Found"), '404 Not Found');
}
$page_output->addScriptFile('tables.js', 'horde');
$page_output->addScriptFile('quickfinder.js', 'horde');
Chora::header($title);
echo Chora::getHistoryViews($where)->render('patchsets');
require CHORA_TEMPLATES . '/patchsets/header_table.inc';
$diff_img = Horde::img('diff.png', _("Diff"));
reset($patchsets);
while (list($id, $patchset) = each($patchsets)) {
    $patchset_link = Chora::url('commit', $where, array('commit' => $id))->link(array('title' => $id)) . htmlspecialchars($VC->abbrev($id)) . '</a>';
    $commitDate = Chora::formatDate($patchset['date']);
    $readableDate = Chora::readableTime($patchset['date'], true);
    $author = Chora::showAuthorName($patchset['author'], true);
    $logMessage = Chora::formatLogMessage($patchset['log']);
    $tags = array_merge($patchset['branch'], $patchset['tags']);
    require CHORA_TEMPLATES . '/patchsets/ps.inc';
}
require CHORA_TEMPLATES . '/patchsets/footer.inc';
$page_output->footer();
All Usage Examples Of Chora::readableTime