Guest User

Untitled

a guest
Jan 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. function humanizeDuration ($secs) {
  2. $secs = ($secs<1)? 1 : $secs;
  3. $tokens = array (
  4. 31536000 => 'year',
  5. 2592000 => 'month',
  6. 604800 => 'week',
  7. 86400 => 'day',
  8. 3600 => 'hour',
  9. 60 => 'minute',
  10. 1 => 'second'
  11. );
  12. foreach ($tokens as $unit => $text) {
  13. if ($secs < $unit) continue;
  14. $numberOfUnits = floor($secs / $unit);
  15. return $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':'');
  16. }
  17. }
Add Comment
Please, Sign In to add comment