From d6518c85e5525627b8ccb41e8a62470baec11cb3 Mon Sep 17 00:00:00 2001 From: dx-tan Date: Wed, 7 Feb 2024 15:24:53 +0700 Subject: [PATCH] Fix: misalign timezone on download file --- cope2n-api/fwd_api/api/accuracy_view.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index 164c979..d69d30b 100644 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -7,6 +7,7 @@ from django.utils import timezone from django.db.models import Q import uuid import os +import pytz from fwd import settings from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiTypes # from drf_spectacular.types import OpenApiString @@ -504,7 +505,8 @@ class AccuracyViewSet(viewsets.ViewSet): raise NotFoundException(excArgs=f"report: {report_id}") report = Report.objects.filter(report_id=report_id).first() # download from s3 to local - tmp_file = "/tmp/" + report.subsidiary + "_" + report.start_at.strftime("%Y%m%d") + "_" + report.end_at.strftime("%Y%m%d") + "_created_on_" + report.created_at.strftime("%Y%m%d") + ".xlsx" + target_timezone = pytz.timezone(settings.TIME_ZONE) + tmp_file = "/tmp/" + report.subsidiary + "_" + report.start_at.astimezone(target_timezone).strftime("%Y%m%d") + "_" + report.end_at.astimezone(target_timezone).strftime("%Y%m%d") + "_created_on_" + report.created_at.astimezone(target_timezone).strftime("%Y%m%d") + ".xlsx" os.makedirs("/tmp", exist_ok=True) if not report.S3_file_name: raise NotFoundException(excArgs="S3 file name")