From 4b0d8ec636bf087213409c750459a3e57416fde1 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 12 Oct 2016 09:20:32 +0100 Subject: [PATCH] Use days of week, not month for scheduled jobs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Friday at 4pm is easier to understand than 14 October at 4pm, especially when the UI you’ve used to choose this time has talked about days of the week. --- app/__init__.py | 18 ++++++++++++++++++ app/templates/partials/jobs/notifications.html | 2 +- app/templates/views/dashboard/_upcoming.html | 2 +- tests/app/main/views/test_dashboard.py | 4 ++-- tests/app/main/views/test_jobs.py | 3 ++- tests/conftest.py | 2 +- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 17b17c563..375bc677a 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -117,6 +117,7 @@ def create_app(): application.add_template_filter(format_date) application.add_template_filter(format_date_normal) application.add_template_filter(format_date_short) + application.add_template_filter(format_datetime_relative) application.add_template_filter(format_delta) application.add_template_filter(format_notification_status) application.add_template_filter(format_notification_status_as_time) @@ -232,6 +233,23 @@ def format_datetime_short(date): ) +def format_datetime_relative(date): + return '{} at {}'.format( + get_human_day(date), + format_time(date) + ) + + +def get_human_day(time): + # Add 1 hour to get ‘midnight today’ instead of ‘midnight tomorrow’ + time = (gmt_timezones(time) - timedelta(hours=1)).strftime('%A') + if time == datetime.utcnow().strftime('%A'): + return 'today' + if time == (datetime.utcnow() + timedelta(days=1)).strftime('%A'): + return 'tomorrow' + return time + + def format_time(date): return { '12:00AM': 'Midnight', diff --git a/app/templates/partials/jobs/notifications.html b/app/templates/partials/jobs/notifications.html index 408073a39..9ef4ef6ad 100644 --- a/app/templates/partials/jobs/notifications.html +++ b/app/templates/partials/jobs/notifications.html @@ -5,7 +5,7 @@ {% if job.job_status == 'scheduled' %}

- Sending will start at {{ job.scheduled_for|format_time }} + Sending will start {{ job.scheduled_for|format_datetime_relative }}