mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-17 04:59:37 -04:00
notify-api-861 show eastern time
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import datetime
|
||||
|
||||
import pytz
|
||||
from flask import current_app
|
||||
from notifications_utils.recipients import RecipientCSV
|
||||
|
||||
@@ -59,6 +62,10 @@ def get_errors_for_csv(recipients, template_type):
|
||||
return errors
|
||||
|
||||
|
||||
def get_user_preferred_timezone():
|
||||
return "US/Eastern"
|
||||
|
||||
|
||||
def generate_notifications_csv(**kwargs):
|
||||
from app import notification_api_client
|
||||
from app.s3_client.s3_csv_client import s3download
|
||||
@@ -108,6 +115,10 @@ def generate_notifications_csv(**kwargs):
|
||||
**kwargs
|
||||
)
|
||||
for notification in notifications_resp["notifications"]:
|
||||
preferred_tz_created_at = convert_report_date_to_preferred_timezone(
|
||||
notification["created_at"]
|
||||
)
|
||||
|
||||
current_app.logger.info(f"\n\n{notification}")
|
||||
if kwargs.get("job_id"):
|
||||
values = (
|
||||
@@ -126,7 +137,7 @@ def generate_notifications_csv(**kwargs):
|
||||
notification["carrier"],
|
||||
notification["provider_response"],
|
||||
notification["status"],
|
||||
notification["created_at"],
|
||||
preferred_tz_created_at,
|
||||
]
|
||||
)
|
||||
else:
|
||||
@@ -139,7 +150,7 @@ def generate_notifications_csv(**kwargs):
|
||||
notification["carrier"],
|
||||
notification["provider_response"],
|
||||
notification["status"],
|
||||
notification["created_at"],
|
||||
preferred_tz_created_at,
|
||||
]
|
||||
yield Spreadsheet.from_rows([map(str, values)]).as_csv_data
|
||||
|
||||
@@ -148,3 +159,16 @@ def generate_notifications_csv(**kwargs):
|
||||
else:
|
||||
return
|
||||
raise Exception("Should never reach here")
|
||||
|
||||
|
||||
def convert_report_date_to_preferred_timezone(db_date_str_in_utc):
|
||||
date_arr = db_date_str_in_utc.split(" ")
|
||||
db_date_str_in_utc = f"{date_arr[0]}T{date_arr[1]}+00:00"
|
||||
utc_date_obj = datetime.datetime.fromisoformat(db_date_str_in_utc)
|
||||
|
||||
utc_date_obj = utc_date_obj.astimezone(pytz.utc)
|
||||
preferred_timezone = pytz.timezone(get_user_preferred_timezone())
|
||||
preferred_date_obj = utc_date_obj.astimezone(preferred_timezone)
|
||||
preferred_tz_created_at = preferred_date_obj.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
return f"{preferred_tz_created_at} {get_user_preferred_timezone()}"
|
||||
|
||||
Reference in New Issue
Block a user