Guest User

Untitled

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