public static function fuzzyFromOffset($offset, $past = null)
{
if ($offset <= MINUTE) {
$span = 'moments';
} elseif ($offset < MINUTE * 20) {
$span = 'a few minutes';
} elseif ($offset < HOUR) {
$span = 'less than an hour';
} elseif ($offset < HOUR * 4) {
$span = 'a couple of hours';
} elseif ($offset < DAY) {
$span = 'less than a day';
} elseif ($offset < DAY * 2) {
$span = 'about a day';
} elseif ($offset < DAY * 4) {
$span = 'a couple of days';
} elseif ($offset < WEEK) {
$span = 'less than a week';
} elseif ($offset < WEEK * 2) {
$span = 'about a week';
} elseif ($offset < MONTH) {
$span = 'less than a month';
} elseif ($offset < MONTH * 2) {
$span = 'about a month';
} elseif ($offset < MONTH * 4) {
$span = 'a couple of months';
} elseif ($offset < YEAR) {
$span = 'less than a year';
} elseif ($offset < YEAR * 2) {
$span = 'about a year';
} elseif ($offset < YEAR * 4) {
$span = 'a couple of years';
} elseif ($offset < YEAR * 8) {
$span = 'a few years';
} elseif ($offset < YEAR * 12) {
$span = 'about a decade';
} elseif ($offset < YEAR * 24) {
$span = 'a couple of decades';
} elseif ($offset < YEAR * 64) {
$span = 'several decades';
} else {
$span = 'a long time';
}
if ($past === true) {
// This is in the past
return __d('tools', '%s ago', __d('tools', $span));
}
if ($past === false) {
// This in the future
return __d('tools', 'in %s', __d('tools', $span));
}
if ($past !== null) {
// Custom translation
return __d('tools', $past, __d('tools', $span));
}
return __d('tools', $span);
}