Fix timezone display: Convert UTC to local time in players list
This commit is contained in:
29
app/app.py
29
app/app.py
@@ -52,6 +52,7 @@ def create_app(config_name=None):
|
|||||||
register_error_handlers(app)
|
register_error_handlers(app)
|
||||||
register_commands(app)
|
register_commands(app)
|
||||||
register_context_processors(app)
|
register_context_processors(app)
|
||||||
|
register_template_filters(app)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@@ -181,6 +182,34 @@ def register_context_processors(app):
|
|||||||
return {'theme': theme}
|
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
|
# For backwards compatibility and direct running
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = create_app()
|
app = create_app()
|
||||||
|
|||||||
@@ -170,7 +170,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if player.last_seen %}
|
{% if player.last_seen %}
|
||||||
{{ player.last_seen.strftime('%Y-%m-%d %H:%M') }}
|
{{ player.last_seen | localtime }}
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="text-muted">Never</span>
|
<span class="text-muted">Never</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user