summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/emotes/single_page.php4
-rw-r--r--src/utils.php18
2 files changed, 21 insertions, 1 deletions
diff --git a/src/emotes/single_page.php b/src/emotes/single_page.php
index d338565..92b4e24 100644
--- a/src/emotes/single_page.php
+++ b/src/emotes/single_page.php
@@ -118,7 +118,9 @@ include_once "../../src/config.php";
echo $username;
echo "</a>";
- echo ", " . date("d M Y", $emote->get_created_at());
+ echo ', <span title="';
+ echo date("M d, Y H:i:s", $emote->get_created_at());
+ echo ' UTC">about ' . format_timestamp(time() - $emote->get_created_at()) . " ago</span>";
?></td>
</tr>
<tr>
diff --git a/src/utils.php b/src/utils.php
index 59ecad4..4954580 100644
--- a/src/utils.php
+++ b/src/utils.php
@@ -30,4 +30,22 @@ function str_safe(string $s, int|null $max_length, bool $remove_new_lines = true
$output = trim($output);
return $output;
+}
+
+function format_timestamp(int $timestamp_secs)
+{
+ $days = floor($timestamp_secs / (60 * 60 * 24));
+ $hours = floor($timestamp_secs / (60 * 60) % 24);
+ $minutes = floor($timestamp_secs % (60 * 60) / 60);
+ $seconds = floor($timestamp_secs % 60);
+
+ if ($days == 0 && $hours == 0 && $minutes == 0) {
+ return "$seconds second" . ($seconds > 1 ? "s" : "");
+ } else if ($days == 0 && $hours == 0) {
+ return "$minutes minute" . ($minutes > 1 ? "s" : "");
+ } else if ($days == 0) {
+ return "$hours hour" . ($hours > 1 ? "s" : "");
+ } else {
+ return "$days day" . ($days > 1 ? "s" : "");
+ }
} \ No newline at end of file