feat: add timezone to datetime display across the board

- the "Flagged Out-of-date on ..." link in the package action panel does
  not contain a timezone specifier.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-02-05 18:35:50 -08:00
parent e777b7052e
commit 1545eab81d
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
15 changed files with 47 additions and 41 deletions

View file

@ -2,7 +2,7 @@ import copy
import math
from datetime import datetime
from typing import Any, Dict
from typing import Any, Dict, Union
from urllib.parse import quote_plus, urlencode
from zoneinfo import ZoneInfo
@ -148,3 +148,25 @@ def _quote_plus(*args, **kwargs) -> str:
@register_filter("ceil")
def ceil(*args, **kwargs) -> int:
return math.ceil(*args, **kwargs)
@register_function("date_strftime")
@pass_context
def date_strftime(context: Dict[str, Any], dt: Union[int, datetime], fmt: str) \
-> str:
if isinstance(dt, int):
dt = timestamp_to_datetime(dt)
tz = context.get("timezone")
return as_timezone(dt, tz).strftime(fmt)
@register_function("date_display")
@pass_context
def date_display(context: Dict[str, Any], dt: Union[int, datetime]) -> str:
return date_strftime(context, dt, "%Y-%m-%d (%Z)")
@register_function("datetime_display")
@pass_context
def datetime_display(context: Dict[str, Any], dt: Union[int, datetime]) -> str:
return date_strftime(context, dt, "%Y-%m-%d %H:%M (%Z)")

View file

@ -57,7 +57,7 @@
<td>
{{
"Inactive since %s" | tr
| format(inactive_ds.strftime("%Y-%m-%d %H:%M"))
| format(datetime_display(inactive_ds))
}}
</td>
{% endif %}
@ -66,15 +66,14 @@
<tr>
<th>{% trans %}Registration date{% endtrans %}:</th>
<td>
{{ user.RegistrationTS.strftime("%Y-%m-%d") }}
{{ date_display(user.RegistrationTS) }}
</td>
</tr>
{% endif %}
{% if login_ts %}
<tr>
<th>{% trans %}Last Login{% endtrans %}:</th>
{% set login_ds = login_ts | dt | as_timezone(timezone) %}
<td>{{ login_ds.strftime("%Y-%m-%d") }}</td>
<td>{{ date_display(login_ts) }}</td>
</tr>
{% endif %}
<tr>

View file

@ -17,7 +17,7 @@
username,
comment.ID
),
commented_at.strftime("%Y-%m-%d %H:%M"),
datetime_display(comment.CommentTS),
"</a>"
) | safe
}}
@ -25,7 +25,7 @@
{% set edited_on = comment.EditedTS | dt | as_timezone(timezone) %}
<span class="edited">
({{ "edited on %s by %s" | tr
| format(edited_on.strftime('%Y-%m-%d %H:%M'),
| format(datetime_display(comment.EditedTS),
'<a href="/account/%s">%s</a>' | format(
comment.Editor.Username, comment.Editor.Username))
| safe

View file

@ -34,10 +34,9 @@
<li>
<span class="flagged">
<a href="/pkgbase/{{ pkgbase.Name }}/flag-comment">
{% set ood_ts = pkgbase.OutOfDateTS | dt | as_timezone(timezone) %}
{{
"Flagged out-of-date (%s)"
| tr | format(ood_ts.strftime("%Y-%m-%d"))
| tr | format(date_strftime(package.PackageBase.OutOfDateTS, "%Y-%m-%d"))
}}
</a>
</span>

View file

@ -18,8 +18,8 @@
)) if request.user.is_authenticated() else
(comment.User.Username),
'<a href="#comment-%s" class="date">%s</a>' | format(
comment.ID,
commented_at.strftime("%Y-%m-%d %H:%M")
comment.ID,
datetime_display(comment.CommentTS)
)
)
| safe
@ -28,7 +28,7 @@
{% set edited_on = comment.EditedTS | dt | as_timezone(timezone) %}
<span class="edited">
({{ "edited on %s by %s" | tr
| format(edited_on.strftime('%Y-%m-%d %H:%M'),
| format(datetime_display(comment.EditedTS),
'<a href="/account/%s">%s</a>' | format(
comment.Editor.Username, comment.Editor.Username))
| safe

View file

@ -150,14 +150,12 @@
<td>{{ pkgbase.Popularity | number_format(6 if pkgbase.Popularity <= 0.2 else 2) }}</td>
</tr>
<tr>
{% set submitted = pkgbase.SubmittedTS | dt | as_timezone(timezone) %}
<th>{{ "First Submitted" | tr }}:</th>
<td>{{ "%s" | format(submitted.strftime("%Y-%m-%d %H:%M")) }}</td>
<td>{{ datetime_display(pkgbase.SubmittedTS) }}</td>
</tr>
<tr>
<th>{{ "Last Updated" | tr }}:</th>
{% set updated = pkgbase.ModifiedTS | dt | as_timezone(timezone) %}
<td>{{ "%s" | format(updated.strftime("%Y-%m-%d %H:%M")) }}</td>
<td>{{ datetime_display(pkgbase.ModifiedTS) }}</td>
</tr>
</table>

View file

@ -40,7 +40,7 @@
{{ request.User.Username }}
</a>
</td>
<td>{{ requested.strftime("%Y-%m-%d %H:%M") }}</td>
<td>{{ datetime_display(request.RequestTS) }}</td>
<td>{{ request.status_display() | tr }}</td>
</tr>
{% endfor %}

View file

@ -24,8 +24,7 @@
</a>
</td>
<td class="pkg-date">
{% set modified = pkg.PackageBase.ModifiedTS | dt | as_timezone(timezone) %}
{{ modified.strftime("%Y-%m-%d %H:%M") }}
{{ datetime_display(pkg.PackageBase.ModifiedTS) }}
</td>
</tr>
{% endfor %}

View file

@ -21,15 +21,13 @@
</strong>
</div>
{% set submitted = voteinfo.Submitted | dt | as_timezone(timezone) %}
{% set submitter = voteinfo.Submitter.Username %}
{% set submitter_uri = "/account/%s" | format(submitter) %}
{% set submitter = '<a href="%s">%s</a>' | format(submitter_uri, submitter) %}
{% set end = voteinfo.End | dt | as_timezone(timezone) %}
<div class="field submitted">
{{
"Submitted: %s by %s" | tr
| format(submitted.strftime("%Y-%m-%d %H:%M"), submitter)
| format(datetime_display(voteinfo.Submitted), submitter)
| safe
}}
</div>
@ -37,7 +35,7 @@
<div class="field end">
{{ "End" | tr }}:
<strong>
{{ end.strftime("%Y-%m-%d %H:%M") }}
{{ datetime_display(voteinfo.End) }}
</strong>
</div>

View file

@ -47,15 +47,8 @@
<a href="/tu/{{ result.ID }}">{{ agenda }}</a>
</td>
<!-- Convert result.Submitted (timestamp) to datetime,
then apply the request's timezone to it. -->
{% set submitted = result.Submitted | dt | as_timezone(timezone) %}
<td>{{ submitted.strftime("%Y-%m-%d") }}</td>
<!-- Convert result.End (timestamp) to datetime,
then apply the request's timezone to it. -->
{% set end = result.End | dt | as_timezone(timezone) %}
<td>{{ end.strftime("%Y-%m-%d") }}</td>
<td>{{ date_display(result.Submitted) }}</td>
<td>{{ date_display(result.End) }}</td>
<td>
{% if not result.User %}

View file

@ -21,7 +21,7 @@
"following reason:"
| tr | format("<strong>", username, "</strong>",
"<strong>", pkgbase.Name, "</strong>",
"<strong>", flagged_at.strftime("%Y-%m-%d"), "</strong>")
"<strong>", date_display(pkgbase.OutOfDateTS), "</strong>")
| safe
}}
</p>

View file

@ -17,8 +17,7 @@
{{ pkg_vote.User.Username }}
</a>
{% set voted_at = pkg_vote.VoteTS | dt | as_timezone(timezone) %}
({{ voted_at.strftime("%Y-%m-%d %H:%M") }})
({{ datetime_display(pkg_vote.VoteTS) }})
</li>
{% endfor %}
</ul>

View file

@ -60,8 +60,7 @@
{% endif %}
>
{# Date #}
{% set date = result.RequestTS | dt | as_timezone(timezone) %}
{{ date.strftime("%Y-%m-%d %H:%M") }}
{{ datetime_display(result.RequestTS) }}
</td>
<td>
{# Status #}

View file

@ -258,7 +258,7 @@ def check_package_details(content: str, pkg: Package) -> None:
assert pop.text.strip() == number_format(0, 6)
# Check First Submitted
date_fmt = "%Y-%m-%d %H:%M"
date_fmt = "%Y-%m-%d %H:%M (%Z)"
i += 1
first_submitted = rows[i].xpath("./td")[0]
converted_dt = as_timezone(to_dt(pkg.PackageBase.SubmittedTS), "UTC")

View file

@ -16,7 +16,7 @@ from aurweb.models.tu_voteinfo import TUVoteInfo
from aurweb.models.user import User
from aurweb.testing.requests import Request
DATETIME_REGEX = r'^[0-9]{4}-[0-9]{2}-[0-9]{2}$'
DATETIME_REGEX = r'^[0-9]{4}-[0-9]{2}-[0-9]{2} \(.+\)$'
PARTICIPATION_REGEX = r'^1?[0-9]{2}[%]$' # 0% - 100%
@ -523,7 +523,7 @@ def test_tu_running_proposal(client: TestClient,
submitted = details.xpath(
'./div[contains(@class, "submitted")]/text()')[0]
assert re.match(r'^Submitted: \d{4}-\d{2}-\d{2} \d{2}:\d{2} by$',
assert re.match(r'^Submitted: \d{4}-\d{2}-\d{2} \d{2}:\d{2} \(.+\) by$',
submitted.strip()) is not None
submitter = details.xpath('./div[contains(@class, "submitted")]/a')[0]
assert submitter.text.strip() == tu_user.Username
@ -534,7 +534,7 @@ def test_tu_running_proposal(client: TestClient,
assert end_label.strip() == "End:"
end_datetime = end.xpath("./strong/text()")[0]
assert re.match(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
assert re.match(r'^\d{4}-\d{2}-\d{2} \d{2}:\d{2} \(.+\)$',
end_datetime.strip()) is not None
# We have not voted yet. Assert that our voting form is shown.