Guest User

Untitled

a guest
Jun 20th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. static function time_since($since) {
  2. $chunks = array(
  3. array(60 * 60 * 24 * 365 , 'year'),
  4. array(60 * 60 * 24 * 30 , 'month'),
  5. array(60 * 60 * 24 * 7, 'week'),
  6. array(60 * 60 * 24 , 'day'),
  7. array(60 * 60 , 'hour'),
  8. array(60 , 'minute'),
  9. array(1 , 'second')
  10. );
  11.  
  12. for ($i = 0, $j = count($chunks); $i < $j; $i++) {
  13. $seconds = $chunks[$i][0];
  14. $name = $chunks[$i][1];
  15. if (($count = floor($since / $seconds)) != 0) {
  16. break;
  17. }
  18. }
  19.  
  20. $print = ($count == 1) ? '1 '.$name : "$count {$name}s";
  21. return $print;
  22. }
  23.  
  24.  
  25. ////////////
  26.  
  27. echo TwitterSearch::time_since(time() - strtotime($tweet->created_at)).' ago';
Add Comment
Please, Sign In to add comment