fixed human readable date

main
oscar 1 month ago
parent 90f4eb7796
commit 235870676f

@ -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 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) 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 ----- # ----- DB helpers -----
def get_db() -> sqlite3.Connection: def get_db() -> sqlite3.Connection:
if "db" not in g: if "db" not in g:

@ -8,8 +8,8 @@ function onKindChange(kind) {
const presets = document.getElementById('presets'); const presets = document.getElementById('presets');
if (!shareWrap || !presets) return; if (!shareWrap || !presets) return;
if (kind === 'transfer') { if (kind === 'transfer') {
shareWrap.style.display = 'none'; shareWrap.style.display = '';
presets.style.display = 'none'; presets.style.display = '';
} else { } else {
shareWrap.style.display = ''; shareWrap.style.display = '';
presets.style.display = ''; presets.style.display = '';

@ -67,7 +67,7 @@
<section class="card"> <section class="card">
<h2>Stats</h2> <h2>Stats</h2>
<div class="muted">Entries: {{ summary.count }}</div> <div class="muted">Entries: {{ summary.count }}</div>
<div class="muted">Latest: {{ summary.latest or '—' }}</div> <div class="muted">Latest: {{ summary.latest|human_time if summary.latest else '—' }}</div>
<div style="margin-top:8px"> <div style="margin-top:8px">
<span class="tag">Cash Δ: {{ currency }}{{ '%.2f'|format(summary.by_method.cash) }}</span> <span class="tag">Cash Δ: {{ currency }}{{ '%.2f'|format(summary.by_method.cash) }}</span>
<span class="tag">Transfer Δ: {{ currency }}{{ '%.2f'|format(summary.by_method.transfer) }}</span> <span class="tag">Transfer Δ: {{ currency }}{{ '%.2f'|format(summary.by_method.transfer) }}</span>
@ -95,7 +95,7 @@
<tbody> <tbody>
{% for e in entries %} {% for e in entries %}
<tr> <tr>
<td>{{ e.created_at }}</td> <td>{{ e.created_at|human_time }}</td>
<td>{{ e.kind }}</td> <td>{{ e.kind }}</td>
<td>{{ A if e.payer=='A' else B }}</td> <td>{{ A if e.payer=='A' else B }}</td>
<td>{{ e.note or '—' }}</td> <td>{{ e.note or '—' }}</td>

Loading…
Cancel
Save