Html::timestampToString PHP Method

timestampToString() static public method

Make a good string from the unix timestamp $sec
static public timestampToString ( $time, $display_sec = true, $use_days = true ) : string
$time integer timestamp
$display_sec boolean display seconds ? (true by default)
$use_days boolean use days for display ? (true by default)
return string
    static function timestampToString($time, $display_sec = true, $use_days = true)
    {
        $sign = '';
        if ($time < 0) {
            $sign = '- ';
            $time = abs($time);
        }
        $time = floor($time);
        // Force display seconds if time is null
        if ($time < MINUTE_TIMESTAMP) {
            $display_sec = true;
        }
        $units = Toolbox::getTimestampTimeUnits($time);
        if ($use_days) {
            if ($units['day'] > 0) {
                if ($display_sec) {
                    //TRANS: %1$s is the sign (-or empty), %2$d number of days, %3$d number of hours,
                    //       %4$d number of minutes, %5$d number of seconds
                    return sprintf(__('%1$s%2$d days %3$d hours %4$d minutes %5$d seconds'), $sign, $units['day'], $units['hour'], $units['minute'], $units['second']);
                }
                //TRANS:  %1$s is the sign (-or empty), %2$d number of days, %3$d number of hours,
                //        %4$d number of minutes
                return sprintf(__('%1$s%2$d days %3$d hours %4$d minutes'), $sign, $units['day'], $units['hour'], $units['minute']);
            }
        } else {
            if ($units['day'] > 0) {
                $units['hour'] += 24 * $units['day'];
            }
        }
        if ($units['hour'] > 0) {
            if ($display_sec) {
                //TRANS:  %1$s is the sign (-or empty), %2$d number of hours, %3$d number of minutes,
                //        %4$d number of seconds
                return sprintf(__('%1$s%2$d hours %3$d minutes %4$d seconds'), $sign, $units['hour'], $units['minute'], $units['second']);
            }
            //TRANS: %1$s is the sign (-or empty), %2$d number of hours, %3$d number of minutes
            return sprintf(__('%1$s%2$d hours %3$d minutes'), $sign, $units['hour'], $units['minute']);
        }
        if ($units['minute'] > 0) {
            if ($display_sec) {
                //TRANS:  %1$s is the sign (-or empty), %2$d number of minutes,  %3$d number of seconds
                return sprintf(__('%1$s%2$d minutes %3$d seconds'), $sign, $units['minute'], $units['second']);
            }
            //TRANS: %1$s is the sign (-or empty), %2$d number of minutes
            return sprintf(_n('%1$s%2$d minute', '%1$s%2$d minutes', $units['minute']), $sign, $units['minute']);
        }
        if ($display_sec) {
            //TRANS:  %1$s is the sign (-or empty), %2$d number of seconds
            return sprintf(_n('%1$s%2$s second', '%1$s%2$s seconds', $units['second']), $sign, $units['second']);
        }
        return '';
    }

Usage Example

 function displayTotal($output_type)
 {
     if ($this->export_timestamp) {
         return $this->total;
     }
     return Html::timestampToString($this->total, $this->withsec);
 }
All Usage Examples Of Html::timestampToString
Html