mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-16 18:13:54 -05:00
added format_datetime_scheduled_notification to formatters and removed unneccesary format changes
This commit is contained in:
@@ -22,7 +22,7 @@ from notifications_utils.recipients import InvalidPhoneError, validate_phone_num
|
||||
from notifications_utils.take import Take
|
||||
|
||||
from app.utils.csv import get_user_preferred_timezone
|
||||
from app.utils.time import parse_dt, parse_naive_dt
|
||||
from app.utils.time import parse_naive_dt
|
||||
|
||||
|
||||
def apply_html_class(tags, html_file):
|
||||
@@ -93,16 +93,34 @@ def format_datetime_normal(date):
|
||||
)
|
||||
|
||||
|
||||
def format_datetime_scheduled_notification(date):
|
||||
# e.g. April 09, 2024 at 04:00 PM US/Eastern.
|
||||
# Everything except scheduled notifications, the time is always "now".
|
||||
# Scheduled notifications are the exception to the rule.
|
||||
# Here we are formating and displaying the datetime without converting datetime to a different timezone.
|
||||
|
||||
datetime_obj = parse_naive_dt(date)
|
||||
|
||||
format_time_without_tz = datetime_obj.replace(tzinfo=timezone.utc).strftime(
|
||||
"%I:%M %p"
|
||||
)
|
||||
return "{} at {} {}".format(
|
||||
format_date_normal(date), format_time_without_tz, get_user_preferred_timezone()
|
||||
)
|
||||
|
||||
|
||||
def format_datetime_table(date):
|
||||
# example: 03-18-2024 at 04:53 PM, intended for datetimes in tables
|
||||
return "{} at {}".format(format_date_numeric(date), format_time_12h(date))
|
||||
|
||||
|
||||
def format_time_12h(date):
|
||||
date = parse_dt(date)
|
||||
date = parse_naive_dt(date)
|
||||
|
||||
preferred_tz = pytz.timezone(get_user_preferred_timezone())
|
||||
return date.astimezone(preferred_tz).strftime("%I:%M %p")
|
||||
return (
|
||||
date.replace(tzinfo=timezone.utc).astimezone(preferred_tz).strftime("%I:%M %p")
|
||||
)
|
||||
|
||||
|
||||
def format_datetime_relative(date):
|
||||
|
||||
Reference in New Issue
Block a user