diff --git a/src/system/helper/localization.php b/src/system/helper/localization.php index eff2664..f9ca812 100644 --- a/src/system/helper/localization.php +++ b/src/system/helper/localization.php @@ -8,4 +8,30 @@ class Localization { return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]]; } + + public static function time(int $time) { + + $timeDiff = time() - $time; + + if ($timeDiff < 1) { + return _('0 seconds'); + } + + $a = [365 * 24 * 60 * 60 => [_('year'), _('years'), _('years')], + 30 * 24 * 60 * 60 => [_('month'), _('months'), _('months')], + 24 * 60 * 60 => [_('day'), _('days'), _('days')], + 60 * 60 => [_('hour'), _('hours'), _('hours')], + 60 => [_('minute'), _('minutes'), _('minutes')], + 1 => [_('second'), _('seconds'), _('seconds')]]; + + foreach ($a as $secs => $v) { + + $d = $timeDiff / $secs; + + if ($d >= 1) { + $r = round($d); + return sprintf('%s %s ago', $r, self::plural($r, $v)); + } + } +} }