diff --git a/main.py b/main.py index b026914..7b0533b 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,27 @@ DEFAULT_ACTOR = os.environ.get("SPLITBUDDY_ACTOR", "anon") # who is using this DEFAULT_A_SHARE_PCT = os.environ.get("SPLITBUDDY_DEFAULT_A_SHARE_PCT", 66.6667) # <-- you pay 2/3 by default WEBAPP_PORT = os.environ.get("SPLITBUDDY_WEBAPP_PORT", 42069) +# ----- Template filters ----- +@app.template_filter('human_time') +def human_time(value: Any) -> str: + """Format ISO-ish timestamps into a concise human-readable string. + Accepts values like '2025-09-14T18:37' or '2025-09-14T18:37:00Z'. + """ + if not value: + return "" + try: + if isinstance(value, dt.datetime): + d = value + else: + s = str(value).strip() + # fromisoformat doesn't accept trailing 'Z' (UTC); strip it if present + if s.endswith('Z'): + s = s[:-1] + d = dt.datetime.fromisoformat(s) + return d.strftime("%b %d, %Y %H:%M") + except Exception: + return str(value) + # ----- DB helpers ----- def get_db() -> sqlite3.Connection: if "db" not in g: @@ -397,4 +418,4 @@ if __name__ == "__main__": os.makedirs(os.path.dirname(DB_PATH) or ".", exist_ok=True) with app.app_context(): init_db() - app.run(debug=True, port=WEBAPP_PORT) \ No newline at end of file + app.run(debug=True, port=WEBAPP_PORT) diff --git a/static/app.js b/static/app.js index b67d64b..37cce30 100644 --- a/static/app.js +++ b/static/app.js @@ -8,8 +8,8 @@ function onKindChange(kind) { const presets = document.getElementById('presets'); if (!shareWrap || !presets) return; if (kind === 'transfer') { - shareWrap.style.display = 'none'; - presets.style.display = 'none'; + shareWrap.style.display = ''; + presets.style.display = ''; } else { shareWrap.style.display = ''; presets.style.display = ''; diff --git a/templates/index.html b/templates/index.html index f5cb20d..9d8322a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -67,7 +67,7 @@

Stats

Entries: {{ summary.count }}
-
Latest: {{ summary.latest or '—' }}
+
Latest: {{ summary.latest|human_time if summary.latest else '—' }}
Cash Δ: {{ currency }}{{ '%.2f'|format(summary.by_method.cash) }} Transfer Δ: {{ currency }}{{ '%.2f'|format(summary.by_method.transfer) }} @@ -95,7 +95,7 @@ {% for e in entries %} - {{ e.created_at }} + {{ e.created_at|human_time }} {{ e.kind }} {{ A if e.payer=='A' else B }} {{ e.note or '—' }} @@ -117,4 +117,4 @@
- \ No newline at end of file +