-
-
Save beingsane/0ff58a30d00731570da5 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
class JHtmlDHDate | |
{ | |
/** | |
* Outputs a relative time. | |
* | |
* @param mixed $date A string or DateTime object representing the time in the past to compare to now. | |
* | |
* @return string | |
* | |
* @since 1.0.1 | |
*/ | |
public static function ago($date) | |
{ | |
if (!($date instanceof DateTime)) | |
{ | |
$date = new JDate($date); | |
} | |
$interval = date_create('now')->diff($date); | |
if ($interval->y >= 1) | |
{ | |
return DHText::plural('JHTMLDATE_N_YEARS_AGO', $interval->y, $interval->y); | |
} | |
else if ($interval->m >= 1) | |
{ | |
return DHText::plural('JHTMLDATE_N_MONTHS_AGO', $interval->m, $interval->m); | |
} | |
else if ($interval->d >= 1) | |
{ | |
return DHText::plural('JHTMLDATE_N_DAYS_AGO', $interval->d, $interval->d); | |
} | |
else if ($interval->h >= 1) | |
{ | |
return DHText::plural('JHTMLDATE_N_HOURS_AGO', $interval->h, $interval->h); | |
} | |
else if ($interval->i >= 1) | |
{ | |
return DHText::plural('JHTMLDATE_N_MINUTES_AGO', $interval->i, $interval->i); | |
} | |
else { | |
return DHText::plural('JHTMLDATE_N_SECONDS_AGO', $interval->s, $interval->s); | |
} | |
} | |
} |
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
JHTMLDATE_N_SECONDS_AGO="%d seconds ago" | |
JHTMLDATE_N_SECONDS_AGO_1="%d second ago" | |
JHTMLDATE_N_MINUTES_AGO="%d minutes ago" | |
JHTMLDATE_N_MINUTES_AGO_1="%d minutes ago" | |
JHTMLDATE_N_HOURS_AGO="%d hours ago" | |
JHTMLDATE_N_HOURS_AGO_1="%d hour ago" | |
JHTMLDATE_N_DAYS_AGO="%d days ago" | |
JHTMLDATE_N_DAYS_AGO_1="%d day ago" | |
JHTMLDATE_N_MONTHS_AGO="%d months ago" | |
JHTMLDATE_N_MONTHS_AGO_1="%d month ago" | |
JHTMLDATE_N_YEARS_AGO="%d years ago" | |
JHTMLDATE_N_YEARS_AGO_1="%d years ago" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment