Removed server-side relative time.

This commit is contained in:
flash 2023-07-18 23:12:47 +00:00
parent bec58f589f
commit 319f37a313
14 changed files with 63 additions and 69 deletions

View file

@ -139,7 +139,7 @@
.forum__category__activity { .forum__category__activity {
text-align: right; text-align: right;
min-width: 270px; min-width: 270px;
line-height: 1.5em; line-height: 1.4em;
} }
.forum__category__activity__none, .forum__category__activity__none,
.forum__category__activity__details { .forum__category__activity__details {
@ -171,6 +171,7 @@
color: var(--user-colour); color: var(--user-colour);
text-decoration: none; text-decoration: none;
pointer-events: initial; pointer-events: initial;
display: block;
} }
.forum__category__username:hover, .forum__category__username:hover,
.forum__category__username:focus { .forum__category__username:focus {
@ -229,4 +230,7 @@
.forum__category__avatar { .forum__category__avatar {
display: none; display: none;
} }
.forum__category__username {
display: none;
}
} }

View file

@ -1,15 +1,16 @@
<?php <?php
namespace Misuzu; namespace Misuzu;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\Environment as TwigEnvironment;
use Index\ByteFormat; use Index\ByteFormat;
use Index\DateTime;
use Index\Environment; use Index\Environment;
use Misuzu\MisuzuContext; use Misuzu\MisuzuContext;
use Misuzu\Comments\CommentsParser; use Misuzu\Comments\CommentsParser;
use Misuzu\Parsers\Parser; use Misuzu\Parsers\Parser;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\Environment as TwigEnvironment;
final class TwigMisuzu extends AbstractExtension { final class TwigMisuzu extends AbstractExtension {
private MisuzuContext $ctx; private MisuzuContext $ctx;
@ -25,7 +26,7 @@ final class TwigMisuzu extends AbstractExtension {
new TwigFilter('parse_text', fn(string $text, int $parser): string => Parser::instance($parser)->parseText($text)), new TwigFilter('parse_text', fn(string $text, int $parser): string => Parser::instance($parser)->parseText($text)),
new TwigFilter('parse_comment', fn(string $text): string => CommentsParser::parseForDisplay($text)), new TwigFilter('parse_comment', fn(string $text): string => CommentsParser::parseForDisplay($text)),
new TwigFilter('perms_check', 'perms_check'), 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'); return compact('ndx', 'pdo', 'total');
} }
public static $units = [ public function timeFormat(DateTime|string|int $dateTime): string {
'y' => 'year', if(is_string($dateTime))
'm' => 'month', $dateTime = new DateTime($dateTime);
'd' => 'day', elseif(is_int($dateTime))
'h' => 'hour', $dateTime = DateTime::fromUnixTimeSeconds($dateTime);
'i' => 'minute',
's' => 'second',
];
// yoinked from https://github.com/twigphp/Twig-extensions/blob/0c7a08e6de42a3c8f6a68af9628f4c8e4e00de93/src/DateExtension.php $string = '';
public function timeDiff(TwigEnvironment $env, $date, $now = null) { $now = DateTime::now();
$date = \twig_date_converter($env, $date);
$now = \twig_date_converter($env, $now);
$diff = $date->diff($now); $isDiffYear = $now->getYear() !== $dateTime->getYear();
if($isDiffYear || $now->getMonth() !== $dateTime->getMonth() || $now->getDay() !== $dateTime->getDay()) {
foreach(self::$units as $attr => $unit) { $string .= $dateTime->format('M jS');
$count = $diff->{$attr}; if($isDiffYear)
$string .= $dateTime->format(' Y');
if($count !== 0) { $string .= ', ';
if($count !== 1)
$unit .= 's';
return $diff->invert ? "in {$count} {$unit}" : "{$count} {$unit} ago";
}
} }
return 'just now'; $string .= $dateTime->format('G:i T');
return $string;
} }
} }

View file

@ -86,7 +86,7 @@
<time class="comment__date" <time class="comment__date"
title="{{ comment.createdTime|date('r') }}" title="{{ comment.createdTime|date('r') }}"
datetime="{{ comment.createdTime|date('c') }}"> datetime="{{ comment.createdTime|date('c') }}">
{{ comment.createdTime|time_diff }} {{ comment.createdTime|time_format }}
</time> </time>
</a> </a>
{% if comment.pinned %} {% if comment.pinned %}
@ -95,7 +95,7 @@
{% if comment.pinnedTime != comment.createdTime %} {% if comment.pinnedTime != comment.createdTime %}
<time title="{{ comment.pinnedTime|date('r') }}" <time title="{{ comment.pinnedTime|date('r') }}"
datetime="{{ comment.pinnedTime|date('c') }}"> datetime="{{ comment.pinnedTime|date('c') }}">
{{ comment.pinnedTime|time_diff }} {{ comment.pinnedTime|time_format }}
</time> </time>
{% endif %} {% endif %}
{% endapply %}</span> {% endapply %}</span>
@ -181,7 +181,7 @@
</div> </div>
{% elseif not user.commentPerms.can_lock|default(false) and category.locked %} {% elseif not user.commentPerms.can_lock|default(false) and category.locked %}
<div class="comments__notice"> <div class="comments__notice">
This comment section was locked, <time datetime="{{ category.lockedTime|date('c') }}" title="{{ category.lockedTime|date('r') }}">{{ category.lockedTime|time_diff }}</time>. This comment section was locked, <time datetime="{{ category.lockedTime|date('c') }}" title="{{ category.lockedTime|date('r') }}">{{ category.lockedTime|time_format }}</time>.
</div> </div>
{% elseif not user.commentPerms.can_comment|default(false) %} {% elseif not user.commentPerms.can_comment|default(false) %}
<div class="comments__notice"> <div class="comments__notice">
@ -195,7 +195,7 @@
{% if user.commentPerms.can_lock|default(false) and category.locked %} {% if user.commentPerms.can_lock|default(false) and category.locked %}
<div class="comments__notice comments__notice--staff"> <div class="comments__notice comments__notice--staff">
This comment section was locked, <time datetime="{{ category.lockedTime|date('c') }}" title="{{ category.lockedTime|date('r') }}">{{ category.lockedTime|time_diff }}</time>. This comment section was locked, <time datetime="{{ category.lockedTime|date('c') }}" title="{{ category.lockedTime|date('r') }}">{{ category.lockedTime|time_format }}</time>.
</div> </div>
{% endif %} {% endif %}

View file

@ -38,7 +38,7 @@
<a class="changelog__change__date" href="{{ url('changelog-index', {'date': change_info.date}) }}"> <a class="changelog__change__date" href="{{ url('changelog-index', {'date': change_info.date}) }}">
Created Created
<time datetime="{{ change_info.createdTime|date('c') }}" title="{{ change_info.createdTime|date('r') }}"> <time datetime="{{ change_info.createdTime|date('c') }}" title="{{ change_info.createdTime|date('r') }}">
{{ change_info.createdTime|time_diff }} {{ change_info.createdTime|time_format }}
</time> </time>
</a> </a>

View file

@ -39,7 +39,7 @@
<time class="changelog__datetime__text" <time class="changelog__datetime__text"
datetime="{{ change.createdTime|date('c') }}" datetime="{{ change.createdTime|date('c') }}"
title="{{ change.createdTime|date('r') }}"> title="{{ change.createdTime|date('r') }}">
{{ change.createdTime|time_diff }} {{ change.createdTime|time_format }}
</time> </time>
</a> </a>
{% endif %} {% endif %}

View file

@ -184,15 +184,11 @@
</a> </a>
<div class="forum__category__activity__info"> <div class="forum__category__activity__info">
<time datetime="{{ forum.recent_post_created|date('c') }}"
title="{{ forum.recent_post_created|date('r') }}">{{ forum.recent_post_created|time_diff }}</time>
{% if forum.recent_post_user_id is not null %} {% if forum.recent_post_user_id is not null %}
by
<a href="{{ url('user-profile', {'user': forum.recent_post_user_id}) }}" class="forum__category__username" <a href="{{ url('user-profile', {'user': forum.recent_post_user_id}) }}" class="forum__category__username"
style="{{ forum.recent_post_user_colour|html_colour }}"> style="{{ forum.recent_post_user_colour|html_colour }}">{{ forum.recent_post_username }}</a>
{{ forum.recent_post_username }}
</a>
{% endif %} {% endif %}
<time datetime="{{ forum.recent_post_created|date('c') }}" title="{{ forum.recent_post_created|date('r') }}">{{ forum.recent_post_created|time_format }}</time>
</div> </div>
</div> </div>
@ -241,7 +237,7 @@
This topic was locked This topic was locked
<time class="forum__status__emphasis" <time class="forum__status__emphasis"
datetime="{{ locked|date('c') }}" datetime="{{ locked|date('c') }}"
title="{{ locked|date('r') }}">{{ locked|time_diff }}</time>. title="{{ locked|date('r') }}">{{ locked|time_format }}</time>.
{% endif %} {% endif %}
{% endset %} {% endset %}
{{ forum_topic_notice(archived ? 'archive' : 'lock', body) }} {{ forum_topic_notice(archived ? 'archive' : 'lock', body) }}
@ -317,7 +313,7 @@
style="{{ topic.author_colour|html_colour }}">{{ topic.author_name }}</a>, style="{{ topic.author_colour|html_colour }}">{{ topic.author_name }}</a>,
{% endif %} {% endif %}
<time datetime="{{ topic.topic_created|date('c') }}" title="{{ topic.topic_created|date('r') }}">{{ topic.topic_created|time_diff }}</time> <time datetime="{{ topic.topic_created|date('c') }}" title="{{ topic.topic_created|date('r') }}">{{ topic.topic_created|time_format }}</time>
</div> </div>
{% if topic.topic_pages|default(0) > 1 %} {% if topic.topic_pages|default(0) > 1 %}
@ -361,7 +357,7 @@
<a class="forum__topic__activity__post" <a class="forum__topic__activity__post"
href="{{ url('forum-post', {'post': topic.response_id, 'post_fragment': 'p' ~ topic.response_id}) }}"> href="{{ url('forum-post', {'post': topic.response_id, 'post_fragment': 'p' ~ topic.response_id}) }}">
<time datetime="{{ topic.response_created|date('c') }}" <time datetime="{{ topic.response_created|date('c') }}"
title="{{ topic.response_created|date('r') }}">{{ topic.response_created|time_diff }}</time> title="{{ topic.response_created|date('r') }}">{{ topic.response_created|time_format }}</time>
</a> </a>
</div> </div>
@ -427,7 +423,7 @@
{% endif %} {% endif %}
<div class="forum__post__joined"> <div class="forum__post__joined">
joined <time datetime="{{ post.poster_joined|date('c') }}" title="{{ post.poster_joined|date('r') }}">{{ post.poster_joined|time_diff }}</time> joined <time datetime="{{ post.poster_joined|date('c') }}" title="{{ post.poster_joined|date('r') }}">{{ post.poster_joined|time_format }}</time>
</div> </div>
{% else %} {% else %}
<div class="forum__post__username">Deleted User</div> <div class="forum__post__username">Deleted User</div>
@ -440,9 +436,9 @@
<div class="forum__post__details"> <div class="forum__post__details">
<a class="forum__post__datetime" href="{{ post_link }}"> <a class="forum__post__datetime" href="{{ post_link }}">
<time datetime="{{ post.post_created|date('c') }}" title="{{ post.post_created|date('r') }}">{{ post.post_created|time_diff }}</time> <time datetime="{{ post.post_created|date('c') }}" title="{{ post.post_created|date('r') }}">{{ post.post_created|time_format }}</time>
{% if post.post_edited is not null %} {% if post.post_edited is not null %}
(edited <time datetime="{{ post.post_edited|date('c') }}" title="{{ post.post_edited|date('r') }}">{{ post.post_edited|time_diff }}</time>) (edited <time datetime="{{ post.post_edited|date('c') }}" title="{{ post.post_edited|date('r') }}">{{ post.post_edited|time_format }}</time>)
{% endif %} {% endif %}
</a> </a>

View file

@ -57,7 +57,7 @@
</div> </div>
<div class="forum__post__joined"> <div class="forum__post__joined">
joined <time datetime="{{ posting_post.poster_joined|default(posting_info.user_created)|date('c') }}" title="{{ posting_post.poster_joined|default(posting_info.user_created)|date('r') }}">{{ posting_post.poster_joined|default(posting_info.user_created)|time_diff }}</time> joined <time datetime="{{ posting_post.poster_joined|default(posting_info.user_created)|date('c') }}" title="{{ posting_post.poster_joined|default(posting_info.user_created)|date('r') }}">{{ posting_post.poster_joined|default(posting_info.user_created)|time_format }}</time>
</div> </div>
</div> </div>
</div> </div>

View file

@ -103,7 +103,7 @@
{{ latest_user.username }} {{ latest_user.username }}
</div> </div>
<div class="landing__latest__joined"> <div class="landing__latest__joined">
Joined <time datetime="{{ latest_user.createdTime|date('c') }}" title="{{ latest_user.createdTime|date('r') }}">{{ latest_user.createdTime|time_diff }}</time> Joined <time datetime="{{ latest_user.createdTime|date('c') }}" title="{{ latest_user.createdTime|date('r') }}">{{ latest_user.createdTime|time_format }}</time>
</div> </div>
</div> </div>
</a> </a>

View file

@ -175,7 +175,7 @@
<p>{{ post.firstParagraph|parse_text(2)|raw }}</p> <p>{{ post.firstParagraph|parse_text(2)|raw }}</p>
<div class="landingv2-news-post-options"> <div class="landingv2-news-post-options">
<a href="{{ url('news-post', {'post': post.id}) }}" class="landingv2-news-post-option">Continue reading</a> <a href="{{ url('news-post', {'post': post.id}) }}" class="landingv2-news-post-option">Continue reading</a>
| {{ post.createdTime|time_diff }} | {{ post.createdTime|time_format }}
</div> </div>
</div> </div>
{% endfor %} {% endfor %}

View file

@ -62,7 +62,7 @@
<td class="manage-list-setting-value"> <td class="manage-list-setting-value">
<div class="manage-list-setting-value-text"> <div class="manage-list-setting-value-text">
<time datetime="{{ redir.topic_redir_created|date('c') }}" title="{{ redir.topic_redir_created|date('r') }}"> <time datetime="{{ redir.topic_redir_created|date('c') }}" title="{{ redir.topic_redir_created|date('r') }}">
{{ redir.topic_redir_created|time_diff }} {{ redir.topic_redir_created|time_format }}
</time> </time>
</div> </div>
</td> </td>

View file

@ -27,18 +27,18 @@
<div class="manage__user-item__details"> <div class="manage__user-item__details">
<div class="manage__user-item__detail"> <div class="manage__user-item__detail">
<i class="fas fa-user-plus fa-fw"></i> <i class="fas fa-user-plus fa-fw"></i>
<time datetime="{{ user.createdTime|date('c') }}" title="{{ user.createdTime|date('r') }}">{{ user.createdTime|time_diff }}</time> / <time datetime="{{ user.createdTime|date('c') }}" title="{{ user.createdTime|date('r') }}">{{ user.createdTime|time_format }}</time> /
<span>{{ user.registerRemoteAddress }}</span> <span>{{ user.registerRemoteAddress }}</span>
</div> </div>
<div class="manage__user-item__detail"> <div class="manage__user-item__detail">
<i class="fas fa-user-clock fa-fw"></i> <i class="fas fa-user-clock fa-fw"></i>
<time datetime="{{ user.activeTime|date('c') }}" title="{{ user.activeTime|date('r') }}">{{ user.activeTime|time_diff }}</time> / <time datetime="{{ user.activeTime|date('c') }}" title="{{ user.activeTime|date('r') }}">{{ user.activeTime|time_format }}</time> /
<span>{{ user.lastRemoteAddress }}</span> <span>{{ user.lastRemoteAddress }}</span>
</div> </div>
{% if user.isDeleted %} {% if user.isDeleted %}
<div class="manage__user-item__detail"> <div class="manage__user-item__detail">
<i class="fas fa-trash-alt fa-fw"></i> <i class="fas fa-trash-alt fa-fw"></i>
<time datetime="{{ user.deletedTime|date('c') }}" title="{{ user.deletedTime|date('r') }}">{{ user.deletedTime|time_diff }}</time> <time datetime="{{ user.deletedTime|date('c') }}" title="{{ user.deletedTime|date('r') }}">{{ user.deletedTime|time_format }}</time>
</div> </div>
{% endif %} {% endif %}
</div> </div>

View file

@ -24,7 +24,7 @@
<div class="news__preview__date"> <div class="news__preview__date">
Posted Posted
<time datetime="{{ post.post.createdTime|date('c') }}" title="{{ post.post.createdTime|date('r') }}"> <time datetime="{{ post.post.createdTime|date('c') }}" title="{{ post.post.createdTime|date('r') }}">
{{ post.post.createdTime|time_diff }} {{ post.post.createdTime|time_format }}
</time> </time>
</div> </div>
</div> </div>
@ -71,7 +71,7 @@
<div class="news__post__date"> <div class="news__post__date">
Posted Posted
<time datetime="{{ post.createdTime|date('c') }}" title="{{ post.createdTime|date('r') }}"> <time datetime="{{ post.createdTime|date('c') }}" title="{{ post.createdTime|date('r') }}">
{{ post.createdTime|time_diff }} {{ post.createdTime|time_format }}
</time> </time>
</div> </div>
@ -79,7 +79,7 @@
<div class="news__post__date"> <div class="news__post__date">
Updated Updated
<time datetime="{{ post.updatedTime|date('c') }}" title="{{ post.updatedTime|date('r') }}"> <time datetime="{{ post.updatedTime|date('c') }}" title="{{ post.updatedTime|date('r') }}">
{{ post.updatedTime|time_diff }} {{ post.updatedTime|time_format }}
</time> </time>
</div> </div>
{% endif %} {% endif %}

View file

@ -94,7 +94,7 @@
{% if is_date %} {% if is_date %}
<time class="profile__header__stat__value" datetime="{{ stat.value|date('c') }}"> <time class="profile__header__stat__value" datetime="{{ stat.value|date('c') }}">
{{ stat.value|time_diff }} {{ stat.value|time_format }}
</time> </time>
{% else %} {% else %}
<div class="profile__header__stat__value"> <div class="profile__header__stat__value">

View file

@ -72,12 +72,12 @@
<div class="usercard__dates"> <div class="usercard__dates">
<div class="usercard__date" title="{{ user.createdTime|date('r') }}"> <div class="usercard__date" title="{{ user.createdTime|date('r') }}">
Joined <time datetime="{{ user.createdTime|date('c') }}">{{ user.createdTime|time_diff }}</time> Joined <time datetime="{{ user.createdTime|date('c') }}">{{ user.createdTime|time_format }}</time>
</div> </div>
{% if user.hasBeenActive %} {% if user.hasBeenActive %}
<div class="usercard__date" title="{{ user.activeTime|date('r') }}"> <div class="usercard__date" title="{{ user.activeTime|date('r') }}">
Last seen <time datetime="{{ user.activeTime|date('c') }}">{{ user.activeTime|time_diff }}</time> Last seen <time datetime="{{ user.activeTime|date('c') }}">{{ user.activeTime|time_format }}</time>
</div> </div>
{% else %} {% else %}
<div class="usercard__date"> <div class="usercard__date">
@ -160,7 +160,7 @@
<div class="usercard__dates"> <div class="usercard__dates">
{% if user.user_created is defined %} {% if user.user_created is defined %}
<div class="usercard__date" title="{{ user.user_created|date('r') }}"> <div class="usercard__date" title="{{ user.user_created|date('r') }}">
Joined <time datetime="{{ user.user_created|date('c') }}">{{ user.user_created|time_diff }}</time> Joined <time datetime="{{ user.user_created|date('c') }}">{{ user.user_created|time_format }}</time>
</div> </div>
{% endif %} {% endif %}
@ -171,7 +171,7 @@
</div> </div>
{% else %} {% else %}
<div class="usercard__date" title="{{ user.user_active|date('r') }}"> <div class="usercard__date" title="{{ user.user_active|date('r') }}">
Last seen <time datetime="{{ user.user_active|date('c') }}">{{ user.user_active|time_diff }}</time> Last seen <time datetime="{{ user.user_active|date('c') }}">{{ user.user_active|time_format }}</time>
</div> </div>
{% endif %} {% endif %}
{% endif %} {% endif %}
@ -238,7 +238,7 @@
Created Created
</div> </div>
<time class="settings__session__detail__value" datetime="{{ session.createdTime|date('c') }}"> <time class="settings__session__detail__value" datetime="{{ session.createdTime|date('c') }}">
{{ session.createdTime|time_diff }} {{ session.createdTime|time_format }}
</time> </time>
</div> </div>
@ -247,7 +247,7 @@
Expires{% if not session.shouldBumpExpire %} (static){% endif %} Expires{% if not session.shouldBumpExpire %} (static){% endif %}
</div> </div>
<time class="settings__session__detail__value" datetime="{{ session.expiresTime|date('c') }}"> <time class="settings__session__detail__value" datetime="{{ session.expiresTime|date('c') }}">
{{ session.expiresTime|time_diff }} {{ session.expiresTime|time_format }}
</time> </time>
</div> </div>
@ -257,7 +257,7 @@
Last Active Last Active
</div> </div>
<time class="settings__session__detail__value" datetime="{{ session.activeTime|date('c') }}"> <time class="settings__session__detail__value" datetime="{{ session.activeTime|date('c') }}">
{{ session.activeTime|time_diff }} {{ session.activeTime|time_format }}
</time> </time>
</div> </div>
{% endif %} {% endif %}
@ -310,7 +310,7 @@
Attempted Attempted
</div> </div>
<time class="settings__login-attempt__detail__value" datetime="{{ attempt.createdTime|date('c') }}"> <time class="settings__login-attempt__detail__value" datetime="{{ attempt.createdTime|date('c') }}">
{{ attempt.createdTime|time_diff }} {{ attempt.createdTime|time_format }}
</time> </time>
</div> </div>
@ -363,7 +363,7 @@
Date Date
</div> </div>
<time class="settings__account-log__detail__value" datetime="{{ data.createdTime|date('c') }}"> <time class="settings__account-log__detail__value" datetime="{{ data.createdTime|date('c') }}">
{{ data.createdTime|time_diff }} {{ data.createdTime|time_format }}
</time> </time>
</div> </div>
</div> </div>
@ -433,7 +433,7 @@
</div> </div>
<time datetime="{{ warning.createdTime|date('c') }}" title="{{ warning.createdTime|date('r') }}" class="profile__warning__created"> <time datetime="{{ warning.createdTime|date('c') }}" title="{{ warning.createdTime|date('r') }}" class="profile__warning__created">
{{ warning.createdTime|time_diff }} {{ warning.createdTime|time_format }}
</time> </time>
{% if warning.isPermanent %} {% if warning.isPermanent %}