Skip to content

Commit f332cc6

Browse files
Jinyu XuJinyu Xu
authored andcommitted
fix: Fix time display in dashboard recent trades
- Convert datetime to timestamp in backend dashboard API - Improve formatTime function to handle ISO 8601 and RFC 2822 formats
1 parent c5d000e commit f332cc6

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

‎backend_api_python/app/routes/dashboard.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,16 @@ def _truthy(v: Any) -> bool:
354354
""",
355355
(user_id,)
356356
)
357-
recent_trades = cur.fetchall() or []
357+
recent_trades_raw = cur.fetchall() or []
358358
cur.close()
359+
360+
# Convert datetime to timestamp for frontend compatibility
361+
recent_trades = []
362+
for t in recent_trades_raw:
363+
trade = dict(t)
364+
if trade.get('created_at') and hasattr(trade['created_at'], 'timestamp'):
365+
trade['created_at'] = int(trade['created_at'].timestamp())
366+
recent_trades.append(trade)
359367

360368
# Compute performance statistics
361369
perf_stats = _compute_performance_stats(recent_trades)

‎quantdinger_vue/src/views/dashboard/index.vue‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -992,12 +992,20 @@ export default {
992992
formatTime (timestamp) {
993993
if (!timestamp) return '-'
994994
try {
995-
const raw = typeof timestamp === 'string' ? parseInt(timestamp, 10) : Number(timestamp)
996-
if (!raw || Number.isNaN(raw)) return '-'
997-
const ms = raw < 1e12 ? raw * 1000 : raw
998-
const d = new Date(ms)
999-
if (isNaN(d.getTime())) return '-'
1000-
return d.toLocaleString()
995+
let date
996+
// Handle ISO 8601 date strings (e.g., "2024-01-17T01:58:10.000Z")
997+
if (typeof timestamp === 'string' && timestamp.includes('-') && timestamp.includes(':')) {
998+
date = new Date(timestamp)
999+
} else if (typeof timestamp === 'number' || (typeof timestamp === 'string' && /^\d+$/.test(timestamp))) {
1000+
// Handle numeric timestamps (seconds or milliseconds)
1001+
const numTimestamp = typeof timestamp === 'string' ? parseInt(timestamp, 10) : timestamp
1002+
const ms = numTimestamp < 1e12 ? numTimestamp * 1000 : numTimestamp
1003+
date = new Date(ms)
1004+
} else {
1005+
return '-'
1006+
}
1007+
if (isNaN(date.getTime())) return '-'
1008+
return date.toLocaleString()
10011009
} catch (e) {
10021010
return '-'
10031011
}

0 commit comments

Comments
 (0)