diff --git a/backend/app/api/chat_routes.py b/backend/app/api/chat_routes.py index a761f43..b640446 100644 --- a/backend/app/api/chat_routes.py +++ b/backend/app/api/chat_routes.py @@ -236,7 +236,10 @@ class ExportPDFRequest(BaseModel): async def export_chat_pdf(request: ExportPDFRequest, db: AsyncSession = Depends(get_db)): """Export selected chat sessions to PDF""" from sqlalchemy import select, desc, asc - from datetime import datetime + from datetime import datetime, timezone, timedelta + + # Timezone definition (Shanghai) + shanghai_tz = timezone(timedelta(hours=8)) if not request.session_ids: raise HTTPException(status_code=400, detail="No sessions selected") @@ -260,7 +263,13 @@ async def export_chat_pdf(request: ExportPDFRequest, db: AsyncSession = Depends( messages_html = "" for log in logs: - timestamp = log.timestamp.strftime('%Y-%m-%d %H:%M:%S') if log.timestamp else "" + # Convert timestamp to Shanghai time + if log.timestamp: + ts_shanghai = log.timestamp.astimezone(shanghai_tz) if log.timestamp.tzinfo else log.timestamp.replace(tzinfo=timezone.utc).astimezone(shanghai_tz) + timestamp = ts_shanghai.strftime('%Y-%m-%d %H:%M:%S') + else: + timestamp = "" + response_html = markdown.markdown(log.response or "", extensions=['tables', 'fenced_code']) # Add context info (Stock Code / Session) to the header since they are mixed @@ -275,7 +284,6 @@ async def export_chat_pdf(request: ExportPDFRequest, db: AsyncSession = Depends(