/** * @param integer seconds * @return string human readable text */ function fuzzy_seconds($seconds) { if ($seconds <= 0) return FALSE; $w = $seconds / 86400 / 7; $d = $seconds / 86400 % 7; $h = $seconds / 3600 % 24; $m = $seconds / 60 % 60; $s = $seconds % 60; $output = array(); if ($w >= 1) $output[] = "{$w} ".($w == 1 ? 'week' : 'weken'); if ($d >= 1) $output[] = "{$d} ".($d == 1 ? 'dag' : 'dagen'); if ($h >= 1) $output[] = "{$h} ".($h == 1 ? 'uur' : 'uren'); if ($m >= 1) $output[] = "{$m} ".($m == 1 ? 'minuut' : 'minuten'); if ($s >= 1) $output[] = "{$s} ".($s == 1 ? 'seconden' : 'seconden'); return implode(', ', $output); }
Resultaat:
echo fuzzy_seconds(123456);
1 dag, 10 uren, 17 minuten, 36 seconden
Categorieën
PHP