Browse Source

add tme format later support

main
ghost 3 years ago
parent
commit
17edfc4418
  1. 15
      src/system/helper/format.php

15
src/system/helper/format.php

@ -9,9 +9,13 @@ class Format {
return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]]; return $texts[(($number % 100) > 4 && ($number % 100) < 20) ? 2 : $cases[min($number % 10, 5)]];
} }
public static function time(int $time) { public static function time(int $time, bool $ago = true) {
if ($ago) {
$timeDiff = time() - $time; $timeDiff = time() - $time;
} else {
$timeDiff = $time - time();
}
if ($timeDiff < 1) { if ($timeDiff < 1) {
return _('0 seconds'); return _('0 seconds');
@ -30,7 +34,14 @@ class Format {
if ($d >= 1) { if ($d >= 1) {
$r = round($d); $r = round($d);
return sprintf('%s %s ago', $r, self::plural($r, $v));
if ($ago) {
return sprintf(_('%s %s ago'), $r, self::plural($r, $v));
} else {
return sprintf(_('%s %s later'), $r, self::plural($r, $v));
}
} }
} }
} }

Loading…
Cancel
Save