Posted By

ghprod on 12/17/11


Tagged

codeigniter


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

notturnale
adkatrit


Facebook Timespan


 / Published in: PHP
 

Facebook Timespan with Codeigniter

  1. function facebook_timespan($timestamp)
  2. {
  3. if($timestamp == '' or !is_numeric($timestamp))
  4. return '';
  5. $hari = date('l',$timestamp);
  6. $tgl = date('d',$timestamp);
  7. $bln = date('F',$timestamp);
  8. $thn = date('Y',$timestamp);
  9. $pukul = date('H:i',$timestamp);
  10. // timespan dari CI's date helper
  11. $timespan = strtolower(timespan($timestamp));
  12. $timespan = str_replace(',','',$timespan);
  13. $exp = explode(' ',$timespan);
  14. $k = $exp[1];
  15. $v = $exp[0];
  16. if($v > 0)
  17. {
  18. if (stristr($k,'year') OR date('Y') > $thn)
  19. {
  20. return $tgl.' '.$bln.' '.$thn;
  21. }
  22. elseif (stristr($k,'week') OR stristr($k,'month'))
  23. {
  24. return $tgl.' '.$bln.' at '.$pukul;
  25. }
  26. elseif (stristr($k,'day') OR stristr($k,'hour') OR stristr($k,'minute') OR stristr($k,'second'))
  27. {
  28. if($v >= 2 AND stristr($k,'day'))
  29. {
  30. return $hari.' at '.$pukul;
  31. }
  32. elseif (date('j') - date('j', $timestamp) == 1)
  33. {
  34. return 'Yesterday at '.$pukul;
  35. }
  36. elseif ((date('D') == date('D', $timestamp)) AND (($v >= 10) AND stristr($k,'hour')))
  37. {
  38. return 'Today at '.$pukul;
  39. }
  40. elseif ((stristr($k,'hour') AND $v < 10) OR stristr($k,'minute') OR stristr($k,'second'))
  41. {
  42. if(stristr($k,'second') AND $v <= 15)
  43. {
  44. return 'just now';
  45. }
  46. return $v.' '.$k.' ago';
  47. }
  48. else
  49. {
  50. return $hari.' at '.$pukul;
  51. }
  52. }
  53. }
  54. else
  55. {
  56. return 'just now';
  57. }
  58. }

Report this snippet  

You need to login to post a comment.