Exemple #1
0
/**
 * Get a title of duration
 *
 * @param integer Duration in seconds
 * @param array Titles
 * @return string Duration title
 */
function get_duration_title($duration, $titles = array())
{
    $titles = array_merge(array('year' => T_('Last %d years'), 'month' => T_('Last %d months'), 'day' => T_('Last %d days'), 'hour' => T_('Last %d hours'), 'minute' => T_('Last %d minutes'), 'second' => T_('Last %d seconds')), $titles);
    $delay_fields = get_duration_fields($duration);
    if (!empty($delay_fields['years'])) {
        // Years
        return sprintf($titles['year'], $delay_fields['years']);
    } elseif (!empty($delay_fields['months'])) {
        // Months
        return sprintf($titles['month'], $delay_fields['months']);
    } elseif (!empty($delay_fields['days'])) {
        // Days
        return sprintf($titles['day'], $delay_fields['days']);
    } elseif (!empty($delay_fields['hours'])) {
        // Hours
        return sprintf($titles['hour'], $delay_fields['hours']);
    } elseif (!empty($delay_fields['minutes'])) {
        // Minutes
        return sprintf($titles['minute'], $delay_fields['minutes']);
    } else {
        // Seconds
        return sprintf($titles['second'], $delay_fields['seconds']);
    }
}
Exemple #2
0
/**
 * Convert seconds to months, days, hours, minutes and seconds format
 *
 * @param integer seconds
 * @return string
 */
function duration_format($duration, $show_seconds = true)
{
    $result = '';
    $fields = get_duration_fields($duration);
    if ($fields['months'] > 0) {
        $result .= sprintf(T_('%d months'), $fields['months']) . ' ';
    }
    if ($fields['days'] > 0) {
        $result .= sprintf(T_('%d days'), $fields['days']) . ' ';
    }
    if ($fields['hours'] > 0) {
        $result .= sprintf(T_('%d hours'), $fields['hours']) . ' ';
    }
    if ($fields['minutes'] > 0) {
        $result .= sprintf(T_('%d minutes'), $fields['minutes']) . ' ';
    }
    if ($show_seconds && $fields['seconds'] > 0) {
        $result .= sprintf(T_('%d seconds'), $fields['seconds']);
    }
    $result = trim($result);
    if (empty($result)) {
        $result = '0';
    }
    return $result;
}