Convert frontend display to be just UTC (#540)

This changeset converts the display of dates and times to be just UTC to match the recent changes in the backend.  This unwinds a bit of work that was done previously and allows us to start with a clean slate in how we want to approach displaying dates and times going forward. It also adds a bit of explanatory text to help users.

Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
Co-authored-by: stvnrlly <steven.reilly@gsa.gov>
This commit is contained in:
Carlo Costino
2023-06-12 15:49:48 -04:00
committed by GitHub
parent da623c87d6
commit 92d25f5a69
19 changed files with 114 additions and 110 deletions

View File

@@ -15,8 +15,7 @@ class Config(object):
HEADER_COLOUR = '#81878b' # mix(govuk-colour("dark-grey"), govuk-colour("mid-grey"))
LOGO_CDN_DOMAIN = 'static-logos.notifications.service.gov.uk' # TODO use our own CDN
ASSETS_DEBUG = False
TIMEZONE = getenv('TIMEZONE', 'America/New_York')
PY_TIMEZONE = pytz.timezone(TIMEZONE)
PY_TIMEZONE = pytz.utc
# Credentials
ADMIN_CLIENT_SECRET = getenv('ADMIN_CLIENT_SECRET')

View File

@@ -18,7 +18,6 @@ from notifications_utils.recipients import (
validate_phone_number,
)
from notifications_utils.take import Take
from notifications_utils.timezones import convert_utc_to_local_timezone
from app.utils.time import parse_naive_dt
@@ -77,19 +76,19 @@ def format_datetime_numeric(date):
def format_date_numeric(date):
date = parse_naive_dt(date)
return convert_utc_to_local_timezone(date).strftime('%Y-%m-%d')
return date.strftime('%Y-%m-%d')
def format_time_24h(date):
date = parse_naive_dt(date)
return convert_utc_to_local_timezone(date).strftime('%H:%M')
return date.strftime('%H:%M')
def get_human_day(time, date_prefix=''):
# Add 1 minute to transform 00:00 into midnight today instead of midnight tomorrow
time = parse_naive_dt(time)
date = (convert_utc_to_local_timezone(time) - timedelta(minutes=1)).date()
date = (time - timedelta(minutes=1)).date()
now = datetime.now(current_app.config['PY_TIMEZONE'])
if date == (now + timedelta(days=1)).date():
@@ -116,24 +115,24 @@ def format_time(date):
'12:00AM': 'Midnight',
'12:00PM': 'Noon'
}.get(
convert_utc_to_local_timezone(date).strftime('%-I:%M%p'),
convert_utc_to_local_timezone(date).strftime('%-I:%M%p')
date.strftime('%-I:%M%p'),
date.strftime('%-I:%M%p')
).lower()
def format_date(date):
date = parse_naive_dt(date)
return convert_utc_to_local_timezone(date).strftime('%A %d %B %Y')
return date.strftime('%A %d %B %Y')
def format_date_normal(date):
date = parse_naive_dt(date)
return convert_utc_to_local_timezone(date).strftime('%d %B %Y').lstrip('0')
return date.strftime('%d %B %Y').lstrip('0')
def format_date_short(date):
date = parse_naive_dt(date)
return _format_datetime_short(convert_utc_to_local_timezone(date))
return _format_datetime_short(date)
def format_date_human(date):
@@ -149,7 +148,7 @@ def format_datetime_human(date, date_prefix=''):
def format_day_of_week(date):
date = parse_naive_dt(date)
return convert_utc_to_local_timezone(date).strftime('%A')
return date.strftime('%A')
def _format_datetime_short(datetime):

View File

@@ -73,7 +73,7 @@ from app.utils.user_permissions import all_ui_permissions, permission_options
def get_time_value_and_label(future_time):
return (
future_time.astimezone(pytz.utc).replace(tzinfo=None).isoformat(),
'{} at {} ET'.format(
'{} at {} UTC'.format(
get_human_day(future_time.astimezone(current_app.config['PY_TIMEZONE'])),
get_human_time(future_time.astimezone(current_app.config['PY_TIMEZONE']))
)

View File

@@ -3,7 +3,6 @@ from datetime import datetime
from flask import abort, current_app, request, session
from flask_login import AnonymousUserMixin, UserMixin, login_user, logout_user
from notifications_python_client.errors import HTTPError
from notifications_utils.timezones import convert_utc_to_local_timezone
from werkzeug.utils import cached_property
from app.event_handlers import (
@@ -129,11 +128,7 @@ class User(JSONModel, UserMixin):
return False
datetime_string = parse_naive_dt(datetime_string)
changed = parse_naive_dt(self.password_changed_at)
return convert_utc_to_local_timezone(
changed
) > convert_utc_to_local_timezone(
datetime_string
)
return changed > datetime_string
def set_permissions(self, service_id, permissions, folder_permissions, set_by_id):
user_api_client.set_user_permissions(

View File

@@ -12,6 +12,12 @@
<p>Notifys real-time dashboard lets you check the status of any message.</p>
<p>For <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for("main.security") }}">security</a>, this information is only available for seven days after a message has been sent. You can download a report, including a list of sent messages, for your own records.</p>
<p>This page describes the statuses youll see when youre signed in to Notify.</p>
<h2 id="text-message-timezones" class="heading-medium">A note about timezones</h2>
<p>Notify currently uses UTC (Coordinated Universal Time) for managing and displaying all dates and times in the system. This means that when you're scheduling messages to send later, or are looking at the time a message was sent, it will be in the UTC timezone.</p>
<p>You can refer to <a href="https://en.wikipedia.org/wiki/Time_in_the_United_States#United_States_and_regional_time_zones">this chart for help</a> with converting UTC times to your local timezone.</p>
<!-- <p>If youre using the Notify API, read our <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('.documentation') }}">documentation</a> for a list of API statuses.<p>
<h2 id="email-statuses" class="heading-medium">Emails</h2>

View File

@@ -61,6 +61,11 @@
&emsp;
Data available for {{ partials.service_data_retention_days }} days
</p>
<p class="font-body-sm">
<a href="https://en.wikipedia.org/wiki/Time_in_the_United_States#United_States_and_regional_time_zones">View timezone chart</a>
&emsp;
For help with understanding and converting UTC times
</p>
{% endif %}
{{ ajax_block(

View File

@@ -35,7 +35,7 @@
{% elif created_by %}
by {{ created_by.name }}
{% endif %}
{{ created_at|format_datetime_human }}
{{ created_at|format_datetime_human }} UTC
</p>
<div class="">