coderuday21 commited on
Commit
b04dab8
·
1 Parent(s): 0bf1136

Fix history timestamps: append UTC offset so browser converts to local time

Browse files
Files changed (1) hide show
  1. app/main.py +15 -3
app/main.py CHANGED
@@ -3,6 +3,7 @@ import io
3
  import json
4
  import os
5
  import uuid
 
6
  from pathlib import Path
7
  from typing import Optional
8
 
@@ -30,6 +31,17 @@ from .notifier import send_notification
30
  import logging
31
  logger = logging.getLogger(__name__)
32
 
 
 
 
 
 
 
 
 
 
 
 
33
  # Create tables and run migrations without crashing the app (HF Spaces can restart if startup fails)
34
  try:
35
  Base.metadata.create_all(bind=engine, checkfirst=True)
@@ -342,7 +354,7 @@ async def detect(
342
  "beforeThumbUrl": f"/api/overlay/{relative_before_thumb}",
343
  "afterThumbUrl": f"/api/overlay/{relative_after_thumb}",
344
  "notificationSent": notification_sent,
345
- "createdAt": run.created_at.isoformat(),
346
  }
347
 
348
 
@@ -383,7 +395,7 @@ def history(
383
  "overlayUrl": f"/api/overlay/{r.overlay_path}" if r.overlay_path else None,
384
  "beforeThumbUrl": f"/api/overlay/{r.before_thumb_path}" if (getattr(r, "before_thumb_path", None) or "").strip() else None,
385
  "afterThumbUrl": f"/api/overlay/{r.after_thumb_path}" if (getattr(r, "after_thumb_path", None) or "").strip() else None,
386
- "createdAt": r.created_at.isoformat(),
387
  }
388
  for r in runs
389
  ]
@@ -422,7 +434,7 @@ def get_run(
422
  "beforeFullUrl": f"/api/overlay/{run.before_full_path}" if (getattr(run, "before_full_path", None) or "").strip() else None,
423
  "beforeThumbUrl": f"/api/overlay/{run.before_thumb_path}" if (getattr(run, "before_thumb_path", None) or "").strip() else None,
424
  "afterThumbUrl": f"/api/overlay/{run.after_thumb_path}" if (getattr(run, "after_thumb_path", None) or "").strip() else None,
425
- "createdAt": run.created_at.isoformat(),
426
  }
427
 
428
 
 
3
  import json
4
  import os
5
  import uuid
6
+ from datetime import timezone
7
  from pathlib import Path
8
  from typing import Optional
9
 
 
31
  import logging
32
  logger = logging.getLogger(__name__)
33
 
34
+
35
+ def _isoformat_utc(dt):
36
+ """Return an ISO-8601 string with explicit +00:00 so the browser can
37
+ convert to local time. SQLite strips tzinfo on read, so naive datetimes
38
+ that we know are UTC need the suffix added back."""
39
+ if dt is None:
40
+ return None
41
+ if dt.tzinfo is None:
42
+ dt = dt.replace(tzinfo=timezone.utc)
43
+ return dt.isoformat()
44
+
45
  # Create tables and run migrations without crashing the app (HF Spaces can restart if startup fails)
46
  try:
47
  Base.metadata.create_all(bind=engine, checkfirst=True)
 
354
  "beforeThumbUrl": f"/api/overlay/{relative_before_thumb}",
355
  "afterThumbUrl": f"/api/overlay/{relative_after_thumb}",
356
  "notificationSent": notification_sent,
357
+ "createdAt": _isoformat_utc(run.created_at),
358
  }
359
 
360
 
 
395
  "overlayUrl": f"/api/overlay/{r.overlay_path}" if r.overlay_path else None,
396
  "beforeThumbUrl": f"/api/overlay/{r.before_thumb_path}" if (getattr(r, "before_thumb_path", None) or "").strip() else None,
397
  "afterThumbUrl": f"/api/overlay/{r.after_thumb_path}" if (getattr(r, "after_thumb_path", None) or "").strip() else None,
398
+ "createdAt": _isoformat_utc(r.created_at),
399
  }
400
  for r in runs
401
  ]
 
434
  "beforeFullUrl": f"/api/overlay/{run.before_full_path}" if (getattr(run, "before_full_path", None) or "").strip() else None,
435
  "beforeThumbUrl": f"/api/overlay/{run.before_thumb_path}" if (getattr(run, "before_thumb_path", None) or "").strip() else None,
436
  "afterThumbUrl": f"/api/overlay/{run.after_thumb_path}" if (getattr(run, "after_thumb_path", None) or "").strip() else None,
437
+ "createdAt": _isoformat_utc(run.created_at),
438
  }
439
 
440