From 319f37a31384246f1c68a8a8a9863ef422dff805 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 18 Jul 2023 23:12:47 +0000 Subject: [PATCH] Removed server-side relative time. --- assets/misuzu.css/forum/categories.css | 8 +++-- src/TwigMisuzu.php | 50 ++++++++++++-------------- templates/_layout/comments.twig | 8 ++--- templates/changelog/change.twig | 2 +- templates/changelog/macros.twig | 2 +- templates/forum/macros.twig | 20 +++++------ templates/forum/posting.twig | 2 +- templates/home/home.twig | 2 +- templates/home/landing.twig | 2 +- templates/manage/forum/redirs.twig | 2 +- templates/manage/users/users.twig | 6 ++-- templates/news/macros.twig | 6 ++-- templates/profile/_layout/header.twig | 2 +- templates/user/macros.twig | 20 +++++------ 14 files changed, 63 insertions(+), 69 deletions(-) diff --git a/assets/misuzu.css/forum/categories.css b/assets/misuzu.css/forum/categories.css index efd55e5..3e579bf 100644 --- a/assets/misuzu.css/forum/categories.css +++ b/assets/misuzu.css/forum/categories.css @@ -139,7 +139,7 @@ .forum__category__activity { text-align: right; min-width: 270px; - line-height: 1.5em; + line-height: 1.4em; } .forum__category__activity__none, .forum__category__activity__details { @@ -171,6 +171,7 @@ color: var(--user-colour); text-decoration: none; pointer-events: initial; + display: block; } .forum__category__username:hover, .forum__category__username:focus { @@ -229,4 +230,7 @@ .forum__category__avatar { display: none; } -} \ No newline at end of file + .forum__category__username { + display: none; + } +} diff --git a/src/TwigMisuzu.php b/src/TwigMisuzu.php index 0cf2b10..06a7655 100644 --- a/src/TwigMisuzu.php +++ b/src/TwigMisuzu.php @@ -1,15 +1,16 @@ Parser::instance($parser)->parseText($text)), new TwigFilter('parse_comment', fn(string $text): string => CommentsParser::parseForDisplay($text)), new TwigFilter('perms_check', 'perms_check'), - new TwigFilter('time_diff', [$this, 'timeDiff'], ['needs_environment' => true]), + new TwigFilter('time_format', [$this, 'timeFormat']), ]; } @@ -53,32 +54,25 @@ final class TwigMisuzu extends AbstractExtension { return compact('ndx', 'pdo', 'total'); } - public static $units = [ - 'y' => 'year', - 'm' => 'month', - 'd' => 'day', - 'h' => 'hour', - 'i' => 'minute', - 's' => 'second', - ]; + public function timeFormat(DateTime|string|int $dateTime): string { + if(is_string($dateTime)) + $dateTime = new DateTime($dateTime); + elseif(is_int($dateTime)) + $dateTime = DateTime::fromUnixTimeSeconds($dateTime); - // yoinked from https://github.com/twigphp/Twig-extensions/blob/0c7a08e6de42a3c8f6a68af9628f4c8e4e00de93/src/DateExtension.php - public function timeDiff(TwigEnvironment $env, $date, $now = null) { - $date = \twig_date_converter($env, $date); - $now = \twig_date_converter($env, $now); + $string = ''; + $now = DateTime::now(); - $diff = $date->diff($now); - - foreach(self::$units as $attr => $unit) { - $count = $diff->{$attr}; - - if($count !== 0) { - if($count !== 1) - $unit .= 's'; - return $diff->invert ? "in {$count} {$unit}" : "{$count} {$unit} ago"; - } + $isDiffYear = $now->getYear() !== $dateTime->getYear(); + if($isDiffYear || $now->getMonth() !== $dateTime->getMonth() || $now->getDay() !== $dateTime->getDay()) { + $string .= $dateTime->format('M jS'); + if($isDiffYear) + $string .= $dateTime->format(' Y'); + $string .= ', '; } - return 'just now'; + $string .= $dateTime->format('G:i T'); + + return $string; } } diff --git a/templates/_layout/comments.twig b/templates/_layout/comments.twig index ee01b42..55e01a5 100644 --- a/templates/_layout/comments.twig +++ b/templates/_layout/comments.twig @@ -86,7 +86,7 @@ {% if comment.pinned %} @@ -95,7 +95,7 @@ {% if comment.pinnedTime != comment.createdTime %} {% endif %} {% endapply %} @@ -181,7 +181,7 @@ {% elseif not user.commentPerms.can_lock|default(false) and category.locked %}
- This comment section was locked, . + This comment section was locked, .
{% elseif not user.commentPerms.can_comment|default(false) %}
@@ -195,7 +195,7 @@ {% if user.commentPerms.can_lock|default(false) and category.locked %}
- This comment section was locked, . + This comment section was locked, .
{% endif %} diff --git a/templates/changelog/change.twig b/templates/changelog/change.twig index dcc26b2..4d33d0d 100644 --- a/templates/changelog/change.twig +++ b/templates/changelog/change.twig @@ -38,7 +38,7 @@ Created diff --git a/templates/changelog/macros.twig b/templates/changelog/macros.twig index 278253b..23a3098 100644 --- a/templates/changelog/macros.twig +++ b/templates/changelog/macros.twig @@ -39,7 +39,7 @@ {% endif %} diff --git a/templates/forum/macros.twig b/templates/forum/macros.twig index da6345a..3d5bee1 100644 --- a/templates/forum/macros.twig +++ b/templates/forum/macros.twig @@ -184,15 +184,11 @@
- {% if forum.recent_post_user_id is not null %} - by - {{ forum.recent_post_username }} - + style="{{ forum.recent_post_user_colour|html_colour }}">{{ forum.recent_post_username }} {% endif %} +
@@ -241,7 +237,7 @@ This topic was locked . + title="{{ locked|date('r') }}">{{ locked|time_format }}. {% endif %} {% endset %} {{ forum_topic_notice(archived ? 'archive' : 'lock', body) }} @@ -317,7 +313,7 @@ style="{{ topic.author_colour|html_colour }}">{{ topic.author_name }}, {% endif %} - + {% if topic.topic_pages|default(0) > 1 %} @@ -361,7 +357,7 @@ + title="{{ topic.response_created|date('r') }}">{{ topic.response_created|time_format }} @@ -427,7 +423,7 @@ {% endif %}
- joined + joined
{% else %}
Deleted User
@@ -440,9 +436,9 @@
diff --git a/templates/forum/posting.twig b/templates/forum/posting.twig index b859ae1..e036c29 100644 --- a/templates/forum/posting.twig +++ b/templates/forum/posting.twig @@ -57,7 +57,7 @@
- joined + joined
diff --git a/templates/home/home.twig b/templates/home/home.twig index fd7b7c9..43ea30f 100644 --- a/templates/home/home.twig +++ b/templates/home/home.twig @@ -103,7 +103,7 @@ {{ latest_user.username }}
- Joined + Joined
diff --git a/templates/home/landing.twig b/templates/home/landing.twig index 738f657..1130239 100644 --- a/templates/home/landing.twig +++ b/templates/home/landing.twig @@ -175,7 +175,7 @@

{{ post.firstParagraph|parse_text(2)|raw }}

Continue reading - | {{ post.createdTime|time_diff }} + | {{ post.createdTime|time_format }}
{% endfor %} diff --git a/templates/manage/forum/redirs.twig b/templates/manage/forum/redirs.twig index 370b339..ec757a2 100644 --- a/templates/manage/forum/redirs.twig +++ b/templates/manage/forum/redirs.twig @@ -62,7 +62,7 @@
diff --git a/templates/manage/users/users.twig b/templates/manage/users/users.twig index b2156c8..a770446 100644 --- a/templates/manage/users/users.twig +++ b/templates/manage/users/users.twig @@ -27,18 +27,18 @@
- / + / {{ user.registerRemoteAddress }}
- / + / {{ user.lastRemoteAddress }}
{% if user.isDeleted %}
- +
{% endif %}
diff --git a/templates/news/macros.twig b/templates/news/macros.twig index 83d7839..6f08412 100644 --- a/templates/news/macros.twig +++ b/templates/news/macros.twig @@ -24,7 +24,7 @@
Posted
@@ -71,7 +71,7 @@
Posted
@@ -79,7 +79,7 @@
Updated
{% endif %} diff --git a/templates/profile/_layout/header.twig b/templates/profile/_layout/header.twig index f681e7c..fd78c0a 100644 --- a/templates/profile/_layout/header.twig +++ b/templates/profile/_layout/header.twig @@ -94,7 +94,7 @@ {% if is_date %} {% else %}
diff --git a/templates/user/macros.twig b/templates/user/macros.twig index 60f6bd9..949f770 100644 --- a/templates/user/macros.twig +++ b/templates/user/macros.twig @@ -72,12 +72,12 @@
- Joined + Joined
{% if user.hasBeenActive %}
- Last seen + Last seen
{% else %}
@@ -160,7 +160,7 @@
{% if user.user_created is defined %}
- Joined + Joined
{% endif %} @@ -171,7 +171,7 @@
{% else %}
- Last seen + Last seen
{% endif %} {% endif %} @@ -238,7 +238,7 @@ Created
@@ -247,7 +247,7 @@ Expires{% if not session.shouldBumpExpire %} (static){% endif %}
@@ -257,7 +257,7 @@ Last Active {% endif %} @@ -310,7 +310,7 @@ Attempted @@ -363,7 +363,7 @@ Date @@ -433,7 +433,7 @@ {% if warning.isPermanent %}