Fix timezone to Sydney
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from flask import Flask
|
||||
from app.config import Config
|
||||
from app.db import init_db, close_db
|
||||
|
||||
SYDNEY_TZ = timezone(timedelta(hours=11))
|
||||
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
@@ -11,6 +14,15 @@ def create_app():
|
||||
init_db(app)
|
||||
app.teardown_appcontext(close_db)
|
||||
|
||||
# Jinja2 filter: convert UTC to Sydney time
|
||||
@app.template_filter('sydney')
|
||||
def sydney_time_filter(dt, fmt='%d %b %Y, %H:%M'):
|
||||
if dt is None:
|
||||
return ''
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.replace(tzinfo=timezone.utc)
|
||||
return dt.astimezone(SYDNEY_TZ).strftime(fmt)
|
||||
|
||||
# Register blueprints
|
||||
from app.routes.auth import bp as auth_bp
|
||||
from app.routes.dashboard import bp as dashboard_bp
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from flask import Blueprint, jsonify
|
||||
from app import SYDNEY_TZ
|
||||
from app.auth import login_required
|
||||
from app.db import query
|
||||
from datetime import timezone
|
||||
|
||||
bp = Blueprint("api", __name__, url_prefix="/api")
|
||||
|
||||
@@ -16,7 +18,7 @@ def chart_data(user_id):
|
||||
(user_id,),
|
||||
)
|
||||
|
||||
labels = [c["checked_in_at"].strftime("%d %b") for c in checkins]
|
||||
labels = [c["checked_in_at"].replace(tzinfo=timezone.utc).astimezone(SYDNEY_TZ).strftime("%d %b") for c in checkins]
|
||||
weights = [float(c["weight_kg"]) for c in checkins]
|
||||
bmis = [float(c["bmi"]) if c["bmi"] else None for c in checkins]
|
||||
|
||||
@@ -88,7 +90,7 @@ def weekly_change(user_id):
|
||||
prev_w = float(checkins[i - 1]["weight_kg"])
|
||||
curr_w = float(checkins[i]["weight_kg"])
|
||||
change = round(curr_w - prev_w, 1)
|
||||
label = checkins[i]["checked_in_at"].strftime("%d %b")
|
||||
label = checkins[i]["checked_in_at"].replace(tzinfo=timezone.utc).astimezone(SYDNEY_TZ).strftime("%d %b")
|
||||
labels.append(label)
|
||||
changes.append(change)
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@
|
||||
<div style="font-weight: 600; font-size: 1.1rem;">{{ '%.1f' % (c.weight_kg | float) }} kg</div>
|
||||
<div class="activity-detail">
|
||||
{% if c.bmi %}BMI {{ '%.1f' % (c.bmi | float) }} · {% endif %}
|
||||
{{ c.checked_in_at.strftime('%d %b %Y, %H:%M') }}
|
||||
{{ c.checked_in_at | sydney }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -131,7 +131,7 @@
|
||||
<div class="activity-content">
|
||||
<div class="activity-name">{{ a.display_name or a.username }}</div>
|
||||
<div class="activity-detail">Logged {{ '%.1f' % (a.weight_kg | float) }} kg · {{
|
||||
a.checked_in_at.strftime('%d %b, %H:%M') }}</div>
|
||||
a.checked_in_at | sydney('%d %b, %H:%M') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<tr id="checkin-{{ c.id }}">
|
||||
<td>{{ c.checked_in_at.strftime('%d %b %Y, %H:%M') }}</td>
|
||||
<td>{{ c.checked_in_at | sydney }}</td>
|
||||
<td style="font-weight: 600;">{{ '%.1f' % (c.weight_kg | float) }} kg</td>
|
||||
<td>{{ '%.1f' % (c.bmi | float) if c.bmi else '—' }}</td>
|
||||
<td>{{ c.notes or '—' }}</td>
|
||||
|
||||
Reference in New Issue
Block a user