Use days of week, not month for scheduled jobs

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.
This commit is contained in:
Chris Hill-Scott
2016-10-12 09:20:32 +01:00
parent 103e09e3a0
commit 4b0d8ec636
6 changed files with 25 additions and 6 deletions

View File

@@ -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',

View File

@@ -5,7 +5,7 @@
{% if job.job_status == 'scheduled' %}
<p>
Sending will start at {{ job.scheduled_for|format_time }}
Sending will start {{ job.scheduled_for|format_datetime_relative }}
</p>
<div class="page-footer">
<form method="post">

View File

@@ -23,7 +23,7 @@
<div class="file-list">
<a class="file-list-filename" href="{{ url_for('.view_job', service_id=current_service.id, job_id=item.id) }}">{{ item.original_file_name }}</a>
<span class="file-list-hint">
Sending at {{ item.scheduled_for|format_time }}
Sending {{ item.scheduled_for|format_datetime_relative }}
</span>
</div>
{% endcall %}

View File

@@ -194,10 +194,10 @@ def test_should_show_upcoming_jobs_on_dashboard(
assert len(table_rows) == 2
assert 'send_me_later.csv' in table_rows[0].find_all('th')[0].text
assert 'Sending at 11:09am' in table_rows[0].find_all('th')[0].text
assert 'Sending today at 11:09am' in table_rows[0].find_all('th')[0].text
assert table_rows[0].find_all('td')[0].text.strip() == '1'
assert 'even_later.csv' in table_rows[1].find_all('th')[0].text
assert 'Sending at 11:09pm' in table_rows[1].find_all('th')[0].text
assert 'Sending today at 11:09pm' in table_rows[1].find_all('th')[0].text
assert table_rows[1].find_all('td')[0].text.strip() == '1'

View File

@@ -142,6 +142,7 @@ def test_should_show_job_in_progress(
assert page.find('p', {'class': 'hint'}).text.strip() == 'Report is 50% complete…'
@freeze_time("2016-01-01T00:00:00.061258")
def test_should_show_scheduled_job(
app_,
service_one,
@@ -162,7 +163,7 @@ def test_should_show_scheduled_job(
assert response.status_code == 200
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
assert page.find('main').find_all('p')[2].text.strip() == 'Sending will start at midnight'
assert page.find('main').find_all('p')[2].text.strip() == 'Sending will start today at midnight'
assert page.find('input', {'type': 'submit', 'value': 'Cancel sending'})

View File

@@ -903,7 +903,7 @@ def mock_get_scheduled_job(mocker, api_user_active):
api_user_active,
job_id=job_id,
job_status='scheduled',
scheduled_for='2016-01-01T00:00:00.061258'
scheduled_for='2016-01-02T00:00:00.061258'
)}
return mocker.patch('app.job_api_client.get_job', side_effect=_get_job)