fix(admin-invites): display times in Asia/Shanghai (CST) instead of UTC

This commit is contained in:
2026-07-06 08:20:14 +08:00
parent 1354032914
commit b10be81505
2 changed files with 18 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
from datetime import datetime from datetime import datetime, timezone, timedelta
from pathlib import Path from pathlib import Path
from uuid import uuid4 from uuid import uuid4
@@ -35,6 +35,20 @@ def _country_flag(code: str) -> str:
templates.env.filters["flag"] = _country_flag templates.env.filters["flag"] = _country_flag
_CST = timezone(timedelta(hours=8))
def _to_local(dt: datetime) -> datetime:
"""Convert UTC datetime to Asia/Shanghai (CST)."""
if dt is None:
return None
if dt.tzinfo is None:
dt = dt.replace(tzinfo=timezone.utc)
return dt.astimezone(_CST)
templates.env.filters["to_local"] = _to_local
def _redirect(url: str) -> RedirectResponse: def _redirect(url: str) -> RedirectResponse:
return RedirectResponse(url, status_code=303) return RedirectResponse(url, status_code=303)

View File

@@ -50,14 +50,14 @@
<div style="display:flex;align-items:center;gap:1rem;flex-wrap:wrap"> <div style="display:flex;align-items:center;gap:1rem;flex-wrap:wrap">
<strong style="font-family:monospace;font-size:1.1rem">{{ c.code }}</strong> <strong style="font-family:monospace;font-size:1.1rem">{{ c.code }}</strong>
<span style="font-size:.8rem;color:var(--text-muted)">创建者: {{ c.creator.username if c.creator else '-' }}</span> <span style="font-size:.8rem;color:var(--text-muted)">创建者: {{ c.creator.username if c.creator else '-' }}</span>
<span style="font-size:.8rem;color:var(--text-muted)">{{ c.created_at.strftime('%Y-%m-%d %H:%M') }}</span> <span style="font-size:.8rem;color:var(--text-muted)">{{ c.created_at|to_local|strftime('%Y-%m-%d %H:%M') }}</span>
{% if c.max_uses is not none %} {% if c.max_uses is not none %}
<span class="badge">已用 {{ c.use_count }} / {{ c.max_uses }}</span> <span class="badge">已用 {{ c.use_count }} / {{ c.max_uses }}</span>
{% else %} {% else %}
<span class="badge">已用 {{ c.use_count }} / ∞</span> <span class="badge">已用 {{ c.use_count }} / ∞</span>
{% endif %} {% endif %}
{% if c.expires_at %} {% if c.expires_at %}
<span class="badge">过期: {{ c.expires_at.strftime('%Y-%m-%d %H:%M') }}</span> <span class="badge">过期: {{ c.expires_at|to_local|strftime('%Y-%m-%d %H:%M') }}</span>
{% else %} {% else %}
<span class="badge">永不过期</span> <span class="badge">永不过期</span>
{% endif %} {% endif %}
@@ -74,7 +74,7 @@
<input type="number" name="max_uses" value="{{ c.max_uses or 1 }}" min="1" class="aif-input aif-short"> <input type="number" name="max_uses" value="{{ c.max_uses or 1 }}" min="1" class="aif-input aif-short">
</div> </div>
<div class="aif-field aif-edit-date" style="display:{% if c.expires_at %}flex{% else %}none{% endif %}"> <div class="aif-field aif-edit-date" style="display:{% if c.expires_at %}flex{% else %}none{% endif %}">
<input type="datetime-local" name="expires_at" value="{{ c.expires_at.strftime('%Y-%m-%dT%H:%M') if c.expires_at else '' }}" class="aif-input aif-date"> <input type="datetime-local" name="expires_at" value="{{ c.expires_at|to_local|strftime('%Y-%m-%dT%H:%M') if c.expires_at else '' }}" class="aif-input aif-date">
</div> </div>
<div class="aif-field aif-btn-wrap"> <div class="aif-field aif-btn-wrap">
<span class="aif-label" style="visibility:hidden">.</span> <span class="aif-label" style="visibility:hidden">.</span>