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 import math
from datetime import datetime from datetime import datetime
from typing import Any, Dict from typing import Any, Dict, Union
from urllib.parse import quote_plus, urlencode from urllib.parse import quote_plus, urlencode
from zoneinfo import ZoneInfo from zoneinfo import ZoneInfo
@ -148,3 +148,25 @@ def _quote_plus(*args, **kwargs) -> str:
@register_filter("ceil") @register_filter("ceil")
def ceil(*args, **kwargs) -> int: def ceil(*args, **kwargs) -> int:
return math.ceil(*args, **kwargs) 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> <td>
{{ {{
"Inactive since %s" | tr "Inactive since %s" | tr
| format(inactive_ds.strftime("%Y-%m-%d %H:%M")) | format(datetime_display(inactive_ds))
}} }}
</td> </td>
{% endif %} {% endif %}
@ -66,15 +66,14 @@
<tr> <tr>
<th>{% trans %}Registration date{% endtrans %}:</th> <th>{% trans %}Registration date{% endtrans %}:</th>
<td> <td>
{{ user.RegistrationTS.strftime("%Y-%m-%d") }} {{ date_display(user.RegistrationTS) }}
</td> </td>
</tr> </tr>
{% endif %} {% endif %}
{% if login_ts %} {% if login_ts %}
<tr> <tr>
<th>{% trans %}Last Login{% endtrans %}:</th> <th>{% trans %}Last Login{% endtrans %}:</th>
{% set login_ds = login_ts | dt | as_timezone(timezone) %} <td>{{ date_display(login_ts) }}</td>
<td>{{ login_ds.strftime("%Y-%m-%d") }}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -47,15 +47,8 @@
<a href="/tu/{{ result.ID }}">{{ agenda }}</a> <a href="/tu/{{ result.ID }}">{{ agenda }}</a>
</td> </td>
<!-- Convert result.Submitted (timestamp) to datetime, <td>{{ date_display(result.Submitted) }}</td>
then apply the request's timezone to it. --> <td>{{ date_display(result.End) }}</td>
{% 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> <td>
{% if not result.User %} {% if not result.User %}

View file

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

View file

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

View file

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

View file

@ -258,7 +258,7 @@ def check_package_details(content: str, pkg: Package) -> None:
assert pop.text.strip() == number_format(0, 6) assert pop.text.strip() == number_format(0, 6)
# Check First Submitted # Check First Submitted
date_fmt = "%Y-%m-%d %H:%M" date_fmt = "%Y-%m-%d %H:%M (%Z)"
i += 1 i += 1
first_submitted = rows[i].xpath("./td")[0] first_submitted = rows[i].xpath("./td")[0]
converted_dt = as_timezone(to_dt(pkg.PackageBase.SubmittedTS), "UTC") 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.models.user import User
from aurweb.testing.requests import Request 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% PARTICIPATION_REGEX = r'^1?[0-9]{2}[%]$' # 0% - 100%
@ -523,7 +523,7 @@ def test_tu_running_proposal(client: TestClient,
submitted = details.xpath( submitted = details.xpath(
'./div[contains(@class, "submitted")]/text()')[0] './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 submitted.strip()) is not None
submitter = details.xpath('./div[contains(@class, "submitted")]/a')[0] submitter = details.xpath('./div[contains(@class, "submitted")]/a')[0]
assert submitter.text.strip() == tu_user.Username assert submitter.text.strip() == tu_user.Username
@ -534,7 +534,7 @@ def test_tu_running_proposal(client: TestClient,
assert end_label.strip() == "End:" assert end_label.strip() == "End:"
end_datetime = end.xpath("./strong/text()")[0] 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 end_datetime.strip()) is not None
# We have not voted yet. Assert that our voting form is shown. # We have not voted yet. Assert that our voting form is shown.