mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 00:07:02 -04:00
getting human time math more correct
This commit is contained in:
@@ -10,7 +10,7 @@ import ago
|
||||
import dateutil
|
||||
import humanize
|
||||
import pytz
|
||||
from flask import Markup, url_for
|
||||
from flask import Markup, current_app, url_for
|
||||
from notifications_utils.field import Field
|
||||
from notifications_utils.formatters import make_quotes_smart
|
||||
from notifications_utils.formatters import nl2br as utils_nl2br
|
||||
@@ -91,7 +91,7 @@ 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()
|
||||
now = datetime.utcnow()
|
||||
now = datetime.now(current_app.config['PY_TIMEZONE'])
|
||||
|
||||
if date == (now + timedelta(days=1)).date():
|
||||
return 'tomorrow'
|
||||
|
||||
@@ -75,7 +75,7 @@ from app.utils.user_permissions import all_ui_permissions, permission_options
|
||||
|
||||
def get_time_value_and_label(future_time):
|
||||
return (
|
||||
future_time.replace(tzinfo=None).isoformat(),
|
||||
future_time.astimezone(pytz.utc).replace(tzinfo=None).isoformat(),
|
||||
'{} at {} ET'.format(
|
||||
get_human_day(future_time.astimezone(current_app.config['PY_TIMEZONE'])),
|
||||
get_human_time(future_time.astimezone(current_app.config['PY_TIMEZONE']))
|
||||
@@ -96,9 +96,9 @@ def get_human_time(time):
|
||||
def get_human_day(time, prefix_today_with='T'):
|
||||
# Add 1 hour to get ‘midnight today’ instead of ‘midnight tomorrow’
|
||||
time = (time - timedelta(hours=1)).strftime('%A')
|
||||
if time == datetime.utcnow().strftime('%A'):
|
||||
if time == datetime.now(current_app.config['PY_TIMEZONE']).strftime('%A'):
|
||||
return '{}oday'.format(prefix_today_with)
|
||||
if time == (datetime.utcnow() + timedelta(days=1)).strftime('%A'):
|
||||
if time == (datetime.now(current_app.config['PY_TIMEZONE']) + timedelta(days=1)).strftime('%A'):
|
||||
return 'Tomorrow'
|
||||
return time
|
||||
|
||||
|
||||
Reference in New Issue
Block a user