summaryrefslogtreecommitdiff
path: root/includes/util/functions.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/util/functions.inc')
-rw-r--r--includes/util/functions.inc57
1 files changed, 41 insertions, 16 deletions
diff --git a/includes/util/functions.inc b/includes/util/functions.inc
index 24b059a..1bfd341 100644
--- a/includes/util/functions.inc
+++ b/includes/util/functions.inc
@@ -389,18 +389,26 @@ if (!function_exists("getMember")) {
}
if (!function_exists("timeAgo")) {
- function timeAgo($time, $french = false): string {
- if (!is_numeric($time)) {
- $time = strtotime($time);
+ function timeAgo($time, $french = false, $isDifference = false, $long = false, $showTense = true): string {
+ $lengths = array("60", "60", "24", "7", "4.35", "12", "100");
+
+ if ($long) {
+ $periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"];
+ } else {
+ $periods = ["sec", "min", "hr", "d", "wk", "mo", "y", "ages"];
}
- $periods = ["sec", "min", "hr", "d", "wk", "mo", "y", "ages"];
- $periods_fr = $periods;
- $lengths = array("60", "60", "24", "7", "4.35", "12", "100");
+ if ($isDifference) {
+ $difference = $time;
+ } else {
+ if (!is_numeric($time)) {
+ $time = strtotime($time);
+ }
- $now = time();
+ $now = time();
+ $difference = $now - $time;
+ }
- $difference = $now - $time;
if ($difference <= 10 && $difference >= 0) {
return $tense = "now";
} elseif ($difference > 0) {
@@ -416,22 +424,39 @@ if (!function_exists("timeAgo")) {
$difference = round($difference);
$period = $periods[$j];
- return "{$difference} {$period} {$tense}";
+
+ if ($showTense) {
+ if ($long) {
+ return "{$difference} {$period}" . ($difference > 1 ? "s" : "") . " {$tense}";
+ } else {
+ return "{$difference} {$period} {$tense}";
+ }
+ } else {
+ if ($long) {
+ return "{$difference} {$period}" . ($difference > 1 ? "s" : "");
+ } else {
+ return "{$difference} {$period}";
+ }
+ }
}
}
if (!function_exists("timeIn")) {
- function timeIn($time): string {
- if (!is_numeric($time)) {
- $time = strtotime($time);
- }
-
+ function timeIn($time, $isDifference = false): string {
$periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"];
$lengths = array("60", "60", "24", "7", "4.35", "12", "100");
- $now = time();
+ if ($isDifference) {
+ $difference = $time;
+ } else {
+ if (!is_numeric($time)) {
+ $time = strtotime($time);
+ }
+
+ $now = time();
+ $difference = $time - $now;
+ }
- $difference = $time - $now;
if ($difference <= 10 && $difference >= 0) {
return $tense = "now";
} elseif ($difference > 0) {