Created
August 31, 2012 12:02
-
-
Save JesusLeon/3551903 to your computer and use it in GitHub Desktop.
PHP Pretty Time addaptation.
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
/** | |
* @desc Pretty time | |
*/ | |
function pretty_time($_DATE_FROM, $_DATE_TO, $_LANG) | |
{ | |
$SECOND = 1; | |
$MINUTE = 60 * $SECOND; | |
$HOUR = 60 * $MINUTE; | |
$DAY = 24 * $HOUR; | |
$MONTH = 30 * $DAY; | |
$delta = strtotime($_DATE_TO) - strtotime($_DATE_FROM); | |
if ($delta < 0) | |
{ | |
return $_LANG['time_the_future']; | |
} | |
if ($delta < 1 * $MINUTE) | |
{ | |
if($delta == 0) | |
return $_LANG['time_just_now']; | |
else if($delta == 1) | |
return $_LANG['time_a_second_ago']; | |
else | |
return str_replace("%CT%", $delta, $_LANG['time_seconds_ago']); | |
} | |
if ($delta < 2 * $MINUTE) | |
{ | |
return $_LANG["time_a_minute_ago"]; | |
} | |
if ($delta < 45 * $MINUTE) | |
{ | |
return str_replace("%CT%", floor($delta / $MINUTE), $_LANG['time_minutes_ago']); | |
} | |
if ($delta < 90 * $MINUTE) | |
{ | |
return $_LANG["time_an_hour_ago"]; | |
} | |
if ($delta < 24 * $HOUR) | |
{ | |
return str_replace("%CT%", floor($delta / $HOUR), $_LANG['time_hours_ago']); | |
} | |
if ($delta < 48 * $HOUR) | |
{ | |
return $_LANG["time_yesterday"]; | |
} | |
if ($delta < 30 * $DAY) | |
{ | |
return str_replace("%CT%", floor($delta / $DAY), $_LANG['time_days_ago']); | |
} | |
if ($delta < 12 * $MONTH) | |
{ | |
$months = floor($delta / $DAY / 30); | |
return $months <= 1 ? $_LANG["time_a_month_ago"] : str_replace("%CT%", $months, $_LANG['time_months_ago']); | |
} | |
else | |
{ | |
$years = floor($delta / $DAY / 365); | |
return $years <= 1 ? $_LANG["time_a_year_ago"] : str_replace("%CT%", $years, $_LANG['time_years_ago']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment