Removed server-side relative time.

This commit is contained in:
Pachira 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 {
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;
}
}
.forum__category__username {
display: none;
}
}

View file

@ -1,15 +1,16 @@
<?php
namespace Misuzu;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\Environment as TwigEnvironment;
use Index\ByteFormat;
use Index\DateTime;
use Index\Environment;
use Misuzu\MisuzuContext;
use Misuzu\Comments\CommentsParser;
use Misuzu\Parsers\Parser;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\Environment as TwigEnvironment;
final class TwigMisuzu extends AbstractExtension {
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_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;
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -57,7 +57,7 @@
</div>
<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>

View file

@ -103,7 +103,7 @@
{{ latest_user.username }}
</div>
<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>
</a>

View file

@ -175,7 +175,7 @@
<p>{{ post.firstParagraph|parse_text(2)|raw }}</p>
<div class="landingv2-news-post-options">
<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>
{% endfor %}

View file

@ -62,7 +62,7 @@
<td class="manage-list-setting-value">
<div class="manage-list-setting-value-text">
<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>
</div>
</td>

View file

@ -27,18 +27,18 @@
<div class="manage__user-item__details">
<div class="manage__user-item__detail">
<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>
</div>
<div class="manage__user-item__detail">
<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>
</div>
{% if user.isDeleted %}
<div class="manage__user-item__detail">
<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>
{% endif %}
</div>

View file

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

View file

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

View file

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