Last active
November 3, 2015 16:17
-
-
Save snarky/991092 to your computer and use it in GitHub Desktop.
Twitter timeDiffInWords
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function timeDiffInWords($time) | |
| { | |
| $second = 1; | |
| $minute = $second * 60; | |
| $hour = $minute * 60; | |
| $day = $hour * 24; | |
| $week = $day * 7; | |
| // Timediff | |
| $timediff = $_SERVER['REQUEST_TIME'] - $time; | |
| // Create timestring | |
| if ($timediff < $second * 7) | |
| return 'right now'; | |
| if ($timediff < $minute) | |
| return floor($timediff / $second) . ' seconds ago'; | |
| if ($timediff < $minute * 2) | |
| return 'about a minute ago'; | |
| if ($timediff < $hour) | |
| return floor($timediff / $minute) . ' minutes ago'; | |
| if ($timediff < $hour * 2) | |
| return 'about an hour ago'; | |
| if ($timediff < $day) | |
| return floor($timediff / $hour) . ' hours ago'; | |
| if ($timediff > $day && $timediff < $day * 2) | |
| return 'yesterday'; | |
| if ($timediff < $week * 52) { | |
| return floor($timediff / $day) . ' days ago'; | |
| } | |
| return 'over a year ago'; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment