Fix timezone display: Convert UTC to local time in players list

This commit is contained in:
2025-11-28 15:22:42 +02:00
parent 610227457c
commit 1fce23d3fd
2 changed files with 30 additions and 1 deletions

View File

@@ -52,6 +52,7 @@ def create_app(config_name=None):
register_error_handlers(app)
register_commands(app)
register_context_processors(app)
register_template_filters(app)
return app
@@ -181,6 +182,34 @@ def register_context_processors(app):
return {'theme': theme}
def register_template_filters(app):
"""Register custom Jinja2 template filters"""
from datetime import datetime, timezone
@app.template_filter('localtime')
def localtime_filter(dt, format='%Y-%m-%d %H:%M'):
"""Convert UTC datetime to local time and format it.
Args:
dt: datetime object in UTC
format: strftime format string
Returns:
Formatted datetime string in local timezone
"""
if dt is None:
return ''
# If datetime is naive (no timezone), assume it's UTC
if dt.tzinfo is None:
dt = dt.replace(tzinfo=timezone.utc)
# Convert to local time
local_dt = dt.astimezone()
return local_dt.strftime(format)
# For backwards compatibility and direct running
if __name__ == '__main__':
app = create_app()