-
-
Save queued/59f1bbdca0c8d4d528ad to your computer and use it in GitHub Desktop.
This file contains 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
public function timeAgo(\Datetime $then) | |
{ | |
$now = new \Datetime('now'); | |
$interval = $then->diff($now); | |
$points = array( | |
'y' => array('year', 'years'), | |
'm' => array('month', 'months'), | |
'd' => array('day', 'days'), | |
'h' => array('hour', 'hours'), | |
'i' => array('minute', 'minutes'), | |
); | |
foreach ($points as $key => $point) { | |
if ($interval->$key >= 1) { | |
$string = $interval->$key == 1 ? $point[0] : $point[1]; | |
return '<time datetime="'.$then->format('Y-m-d H:i:s').'" title="'.$then->format('Y-m-d H:i:s').'">'.$interval->$key.' '.$string.' ago'.'</time>'; | |
} | |
} | |
return 'just now'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment