Fix backup timestamp display to use UTC timezone

The list_backups function was creating timezone-naive datetime objects,
which caused the frontend to incorrectly interpret timestamps.

Now uses datetime.UTC when creating timestamps from file modification time
(consistent with other usage in this file on lines 186, 216), so the ISO
string includes timezone info (+00:00). This allows the browser to properly
convert UTC timestamps to the user's local timezone for display.

Before: Backend sends "2025-12-09T14:12:44" (ambiguous timezone)
After: Backend sends "2025-12-09T14:12:44+00:00" (explicit UTC)

The frontend's toLocaleString() will now correctly convert to local time.
This commit is contained in:
Jim McBride 2025-12-09 08:16:04 -06:00
parent c65df2de89
commit e71e6bc3d7
No known key found for this signature in database
GPG key ID: E02BFB7AB3C895D7

View file

@ -282,10 +282,12 @@ def list_backups() -> list[dict]:
backups = []
for backup_file in sorted(backup_dir.glob("dispatcharr-backup-*.zip"), reverse=True):
# Use UTC timezone so frontend can convert to user's local time
created_time = datetime.datetime.fromtimestamp(backup_file.stat().st_mtime, datetime.UTC)
backups.append({
"name": backup_file.name,
"size": backup_file.stat().st_size,
"created": datetime.datetime.fromtimestamp(backup_file.stat().st_mtime).isoformat(),
"created": created_time.isoformat(),
})
return backups