fix(admin-invites): display times in Asia/Shanghai (CST) instead of UTC
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -35,6 +35,20 @@ def _country_flag(code: str) -> str:
|
||||
|
||||
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:
|
||||
return RedirectResponse(url, status_code=303)
|
||||
|
||||
Reference in New Issue
Block a user