mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
initial timezone pass, which breaks many tests
This commit is contained in:
@@ -12,6 +12,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 = os.environ.get('TIMEZONE', 'America/New_York')
|
||||
|
||||
# Credentials
|
||||
ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET')
|
||||
|
||||
@@ -9,6 +9,7 @@ from numbers import Number
|
||||
import ago
|
||||
import dateutil
|
||||
import humanize
|
||||
import pytz
|
||||
from flask import Markup, url_for
|
||||
from notifications_utils.field import Field
|
||||
from notifications_utils.formatters import make_quotes_smart
|
||||
@@ -18,7 +19,7 @@ from notifications_utils.recipients import (
|
||||
validate_phone_number,
|
||||
)
|
||||
from notifications_utils.take import Take
|
||||
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
|
||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||
|
||||
|
||||
def convert_to_boolean(value):
|
||||
@@ -74,17 +75,18 @@ def format_datetime_numeric(date):
|
||||
|
||||
|
||||
def format_date_numeric(date):
|
||||
return utc_string_to_aware_gmt_datetime(date).strftime('%Y-%m-%d')
|
||||
return convert_utc_to_local_timezone(date).strftime('%Y-%m-%d')
|
||||
|
||||
|
||||
def format_time_24h(date):
|
||||
return utc_string_to_aware_gmt_datetime(date).strftime('%H:%M')
|
||||
return convert_utc_to_local_timezone(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’
|
||||
date = (utc_string_to_aware_gmt_datetime(time) - timedelta(minutes=1)).date()
|
||||
time = dateutil.parser.parse(time, ignoretz=True)
|
||||
date = (convert_utc_to_local_timezone(time) - timedelta(minutes=1)).date()
|
||||
now = datetime.utcnow()
|
||||
|
||||
if date == (now + timedelta(days=1)).date():
|
||||
@@ -106,25 +108,26 @@ def get_human_day(time, date_prefix=''):
|
||||
|
||||
|
||||
def format_time(date):
|
||||
date = dateutil.parser.parse(date, ignoretz=True)
|
||||
return {
|
||||
'12:00AM': 'Midnight',
|
||||
'12:00PM': 'Midday'
|
||||
'12:00PM': 'Noon'
|
||||
}.get(
|
||||
utc_string_to_aware_gmt_datetime(date).strftime('%-I:%M%p'),
|
||||
utc_string_to_aware_gmt_datetime(date).strftime('%-I:%M%p')
|
||||
convert_utc_to_local_timezone(date).strftime('%-I:%M%p'),
|
||||
convert_utc_to_local_timezone(date).strftime('%-I:%M%p')
|
||||
).lower()
|
||||
|
||||
|
||||
def format_date(date):
|
||||
return utc_string_to_aware_gmt_datetime(date).strftime('%A %d %B %Y')
|
||||
return convert_utc_to_local_timezone(date).strftime('%A %d %B %Y')
|
||||
|
||||
|
||||
def format_date_normal(date):
|
||||
return utc_string_to_aware_gmt_datetime(date).strftime('%d %B %Y').lstrip('0')
|
||||
return convert_utc_to_local_timezone(date).strftime('%d %B %Y').lstrip('0')
|
||||
|
||||
|
||||
def format_date_short(date):
|
||||
return _format_datetime_short(utc_string_to_aware_gmt_datetime(date))
|
||||
return _format_datetime_short(convert_utc_to_local_timezone(date))
|
||||
|
||||
|
||||
def format_date_human(date):
|
||||
@@ -139,7 +142,7 @@ def format_datetime_human(date, date_prefix=''):
|
||||
|
||||
|
||||
def format_day_of_week(date):
|
||||
return utc_string_to_aware_gmt_datetime(date).strftime('%A')
|
||||
return convert_utc_to_local_timezone(date).strftime('%A')
|
||||
|
||||
|
||||
def _format_datetime_short(datetime):
|
||||
@@ -155,10 +158,11 @@ def naturaltime_without_indefinite_article(date):
|
||||
|
||||
|
||||
def format_delta(date):
|
||||
date = dateutil.parser.parse(date, ignoretz=True)
|
||||
delta = (
|
||||
datetime.now(timezone.utc)
|
||||
) - (
|
||||
utc_string_to_aware_gmt_datetime(date)
|
||||
convert_utc_to_local_timezone(date).replace(tzinfo=pytz.utc)
|
||||
)
|
||||
if delta < timedelta(seconds=30):
|
||||
return "just now"
|
||||
@@ -168,8 +172,9 @@ def format_delta(date):
|
||||
|
||||
|
||||
def format_delta_days(date):
|
||||
date = dateutil.parser.parse(date, ignoretz=True)
|
||||
now = datetime.now(timezone.utc)
|
||||
date = utc_string_to_aware_gmt_datetime(date)
|
||||
date = convert_utc_to_local_timezone(date).replace(tzinfo=pytz.utc)
|
||||
if date.strftime('%Y-%m-%d') == now.strftime('%Y-%m-%d'):
|
||||
return "today"
|
||||
if date.strftime('%Y-%m-%d') == (now - timedelta(days=1)).strftime('%Y-%m-%d'):
|
||||
|
||||
@@ -4,7 +4,7 @@ from itertools import chain
|
||||
from numbers import Number
|
||||
|
||||
import pytz
|
||||
from flask import Markup, render_template, request
|
||||
from flask import Markup, current_app, render_template, request
|
||||
from flask_login import current_user
|
||||
from flask_wtf import FlaskForm as Form
|
||||
from flask_wtf.file import FileAllowed
|
||||
@@ -77,8 +77,8 @@ def get_time_value_and_label(future_time):
|
||||
return (
|
||||
future_time.replace(tzinfo=None).isoformat(),
|
||||
'{} at {}'.format(
|
||||
get_human_day(future_time.astimezone(pytz.timezone('Europe/London'))),
|
||||
get_human_time(future_time.astimezone(pytz.timezone('Europe/London')))
|
||||
get_human_day(future_time.astimezone(pytz.timezone(current_app.config['TIMEZONE']))),
|
||||
get_human_time(future_time.astimezone(pytz.timezone(current_app.config['TIMEZONE'])))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils.clients.zendesk.zendesk_client import (
|
||||
NotifySupportTicket,
|
||||
)
|
||||
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
|
||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||
|
||||
from app import (
|
||||
billing_api_client,
|
||||
@@ -440,8 +440,8 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id):
|
||||
is_default=is_default
|
||||
)
|
||||
seconds_since_sending = (
|
||||
utc_string_to_aware_gmt_datetime(datetime.utcnow().isoformat()) -
|
||||
utc_string_to_aware_gmt_datetime(notification['created_at'])
|
||||
convert_utc_to_local_timezone(datetime.utcnow().isoformat()) -
|
||||
convert_utc_to_local_timezone(notification['created_at'])
|
||||
).seconds
|
||||
if notification["status"] in FAILURE_STATUSES or (
|
||||
notification["status"] in SENDING_STATUSES and
|
||||
|
||||
@@ -6,7 +6,7 @@ from notifications_utils.letter_timings import (
|
||||
get_letter_timings,
|
||||
letter_can_be_cancelled,
|
||||
)
|
||||
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
|
||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.models import JSONModel, ModelList, PaginatedModelList
|
||||
@@ -150,7 +150,7 @@ class Job(JSONModel):
|
||||
|
||||
if not letter_can_be_cancelled(
|
||||
'created',
|
||||
utc_string_to_aware_gmt_datetime(self.created_at).replace(tzinfo=None)
|
||||
convert_utc_to_local_timezone(self.created_at).replace(tzinfo=None)
|
||||
):
|
||||
return False
|
||||
|
||||
@@ -165,7 +165,7 @@ class Job(JSONModel):
|
||||
# We have to make the time just before 5:30pm because a
|
||||
# letter uploaded at 5:30pm will be printed the next day
|
||||
(
|
||||
utc_string_to_aware_gmt_datetime(self.created_at) - timedelta(minutes=1)
|
||||
convert_utc_to_local_timezone(self.created_at) - timedelta(minutes=1)
|
||||
).astimezone(pytz.utc).isoformat(),
|
||||
long_form=False,
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
from flask import abort, request, session
|
||||
from flask_login import AnonymousUserMixin, UserMixin, login_user, logout_user
|
||||
from notifications_python_client.errors import HTTPError
|
||||
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
|
||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.event_handlers import (
|
||||
@@ -126,9 +126,9 @@ class User(JSONModel, UserMixin):
|
||||
def password_changed_more_recently_than(self, datetime_string):
|
||||
if not self.password_changed_at:
|
||||
return False
|
||||
return utc_string_to_aware_gmt_datetime(
|
||||
return convert_utc_to_local_timezone(
|
||||
self.password_changed_at
|
||||
) > utc_string_to_aware_gmt_datetime(
|
||||
) > convert_utc_to_local_timezone(
|
||||
datetime_string
|
||||
)
|
||||
|
||||
|
||||
@@ -7,17 +7,16 @@ from notifications_utils.formatters import unescaped_formatted_list
|
||||
from notifications_utils.letter_timings import letter_can_be_cancelled
|
||||
from notifications_utils.postal_address import PostalAddress
|
||||
from notifications_utils.timezones import (
|
||||
convert_bst_to_utc,
|
||||
convert_utc_to_bst,
|
||||
utc_string_to_aware_gmt_datetime,
|
||||
convert_local_timezone_to_utc,
|
||||
convert_utc_to_local_timezone,
|
||||
)
|
||||
|
||||
|
||||
def printing_today_or_tomorrow(created_at):
|
||||
print_cutoff = convert_bst_to_utc(
|
||||
convert_utc_to_bst(datetime.utcnow()).replace(hour=17, minute=30)
|
||||
print_cutoff = convert_local_timezone_to_utc(
|
||||
convert_utc_to_local_timezone(datetime.utcnow()).replace(hour=17, minute=30)
|
||||
).replace(tzinfo=pytz.utc)
|
||||
created_at = utc_string_to_aware_gmt_datetime(created_at)
|
||||
created_at = convert_utc_to_local_timezone(created_at)
|
||||
|
||||
if created_at < print_cutoff:
|
||||
return 'today'
|
||||
@@ -31,7 +30,7 @@ def get_letter_printing_statement(status, created_at, long_form=True):
|
||||
decription = 'Printing starts' if long_form else 'Printing'
|
||||
return f'{decription} {printing_today_or_tomorrow(created_at)} at 5:30pm'
|
||||
else:
|
||||
printed_datetime = utc_string_to_aware_gmt_datetime(created_at) + timedelta(hours=6, minutes=30)
|
||||
printed_datetime = convert_utc_to_local_timezone(created_at) + timedelta(hours=6, minutes=30)
|
||||
if printed_datetime.date() == datetime.now().date():
|
||||
return 'Printed today at 5:30pm'
|
||||
elif printed_datetime.date() == datetime.now().date() - timedelta(days=1):
|
||||
|
||||
@@ -2,11 +2,11 @@ from datetime import datetime
|
||||
|
||||
import pytz
|
||||
from dateutil import parser
|
||||
from notifications_utils.timezones import utc_string_to_aware_gmt_datetime
|
||||
from notifications_utils.timezones import convert_utc_to_local_timezone
|
||||
|
||||
|
||||
def get_current_financial_year():
|
||||
now = utc_string_to_aware_gmt_datetime(
|
||||
now = convert_utc_to_local_timezone(
|
||||
datetime.utcnow()
|
||||
)
|
||||
current_month = int(now.strftime('%-m'))
|
||||
|
||||
Reference in New Issue
Block a user