mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Make date of sending relative
This is a friendlier and better way of showing dates anywhere except in a report which might be archived and referred back to later. Bit trickier to implement here because a dat requires ‘on’ beforehand, but we don’t say ‘on today’ in English.
This commit is contained in:
@@ -291,7 +291,7 @@ def format_time_24h(date):
|
|||||||
return utc_string_to_aware_gmt_datetime(date).strftime('%H:%M')
|
return utc_string_to_aware_gmt_datetime(date).strftime('%H:%M')
|
||||||
|
|
||||||
|
|
||||||
def get_human_day(time):
|
def get_human_day(time, date_prefix=''):
|
||||||
|
|
||||||
# Add 1 minute to transform 00:00 into ‘midnight today’ instead of ‘midnight tomorrow’
|
# 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()
|
date = (utc_string_to_aware_gmt_datetime(time) - timedelta(minutes=1)).date()
|
||||||
@@ -304,8 +304,15 @@ def get_human_day(time):
|
|||||||
if date == (now - timedelta(days=1)).date():
|
if date == (now - timedelta(days=1)).date():
|
||||||
return 'yesterday'
|
return 'yesterday'
|
||||||
if date.strftime('%Y') != now.strftime('%Y'):
|
if date.strftime('%Y') != now.strftime('%Y'):
|
||||||
return '{} {}'.format(_format_datetime_short(date), date.strftime('%Y'))
|
return '{} {} {}'.format(
|
||||||
return _format_datetime_short(date)
|
date_prefix,
|
||||||
|
_format_datetime_short(date),
|
||||||
|
date.strftime('%Y'),
|
||||||
|
).strip()
|
||||||
|
return '{} {}'.format(
|
||||||
|
date_prefix,
|
||||||
|
_format_datetime_short(date),
|
||||||
|
).strip()
|
||||||
|
|
||||||
|
|
||||||
def format_time(date):
|
def format_time(date):
|
||||||
@@ -334,6 +341,13 @@ def format_date_human(date):
|
|||||||
return get_human_day(date)
|
return get_human_day(date)
|
||||||
|
|
||||||
|
|
||||||
|
def format_datetime_human(date, date_prefix=''):
|
||||||
|
return '{} at {}'.format(
|
||||||
|
get_human_day(date, date_prefix='on'),
|
||||||
|
format_time(date),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def format_day_of_week(date):
|
def format_day_of_week(date):
|
||||||
return utc_string_to_aware_gmt_datetime(date).strftime('%A')
|
return utc_string_to_aware_gmt_datetime(date).strftime('%A')
|
||||||
|
|
||||||
@@ -746,6 +760,7 @@ def add_template_filters(application):
|
|||||||
format_date_human,
|
format_date_human,
|
||||||
format_date_normal,
|
format_date_normal,
|
||||||
format_date_short,
|
format_date_short,
|
||||||
|
format_datetime_human,
|
||||||
format_datetime_relative,
|
format_datetime_relative,
|
||||||
format_day_of_week,
|
format_day_of_week,
|
||||||
format_delta,
|
format_delta,
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
{% elif created_by %}
|
{% elif created_by %}
|
||||||
by {{ created_by.name }}
|
by {{ created_by.name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
on {{ created_at|format_datetime_short }}
|
{{ created_at|format_datetime_human }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{% if template.template_type == 'letter' %}
|
{% if template.template_type == 'letter' %}
|
||||||
|
|||||||
@@ -152,22 +152,43 @@ def test_notification_status_shows_expected_back_link(
|
|||||||
assert back_link is None
|
assert back_link is None
|
||||||
|
|
||||||
|
|
||||||
@freeze_time("2012-01-01 01:01")
|
@pytest.mark.parametrize('time_of_viewing_page, expected_message', (
|
||||||
|
('2012-01-01 01:01', (
|
||||||
|
"‘sample template’ was sent by Test User today at 1:01am"
|
||||||
|
)),
|
||||||
|
('2012-01-02 01:01', (
|
||||||
|
"‘sample template’ was sent by Test User yesterday at 1:01am"
|
||||||
|
)),
|
||||||
|
('2012-01-03 01:01', (
|
||||||
|
"‘sample template’ was sent by Test User on 1 January at 1:01am"
|
||||||
|
)),
|
||||||
|
('2013-01-03 01:01', (
|
||||||
|
"‘sample template’ was sent by Test User on 1 January 2012 at 1:01am"
|
||||||
|
)),
|
||||||
|
))
|
||||||
def test_notification_page_doesnt_link_to_template_in_tour(
|
def test_notification_page_doesnt_link_to_template_in_tour(
|
||||||
|
mocker,
|
||||||
client_request,
|
client_request,
|
||||||
fake_uuid,
|
fake_uuid,
|
||||||
mock_get_notification,
|
mock_get_notification,
|
||||||
|
time_of_viewing_page,
|
||||||
|
expected_message,
|
||||||
):
|
):
|
||||||
|
|
||||||
page = client_request.get(
|
with freeze_time('2012-01-01 01:01'):
|
||||||
'main.view_notification',
|
notification = create_notification()
|
||||||
service_id=SERVICE_ONE_ID,
|
mocker.patch('app.notification_api_client.get_notification', return_value=notification)
|
||||||
notification_id=fake_uuid,
|
|
||||||
help=3,
|
with freeze_time(time_of_viewing_page):
|
||||||
)
|
page = client_request.get(
|
||||||
|
'main.view_notification',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
notification_id=fake_uuid,
|
||||||
|
help=3,
|
||||||
|
)
|
||||||
|
|
||||||
assert normalize_spaces(page.select('main p:nth-of-type(1)')[0].text) == (
|
assert normalize_spaces(page.select('main p:nth-of-type(1)')[0].text) == (
|
||||||
"‘sample template’ was sent by Test User on 1 January at 1:01am"
|
expected_message
|
||||||
)
|
)
|
||||||
assert len(page.select('main p:nth-of-type(1) a')) == 0
|
assert len(page.select('main p:nth-of-type(1) a')) == 0
|
||||||
|
|
||||||
@@ -196,7 +217,7 @@ def test_notification_page_shows_page_for_letter_notification(
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert normalize_spaces(page.select('main p:nth-of-type(1)')[0].text) == (
|
assert normalize_spaces(page.select('main p:nth-of-type(1)')[0].text) == (
|
||||||
"‘sample template’ was sent by Test User on 1 January at 1:01am"
|
"‘sample template’ was sent by Test User today at 1:01am"
|
||||||
)
|
)
|
||||||
assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == (
|
assert normalize_spaces(page.select('main p:nth-of-type(2)')[0].text) == (
|
||||||
'Printing starts today at 5:30pm'
|
'Printing starts today at 5:30pm'
|
||||||
@@ -230,13 +251,13 @@ def test_notification_page_shows_page_for_letter_notification(
|
|||||||
@pytest.mark.parametrize('is_precompiled_letter, expected_p1, expected_p2, expected_postage', (
|
@pytest.mark.parametrize('is_precompiled_letter, expected_p1, expected_p2, expected_postage', (
|
||||||
(
|
(
|
||||||
True,
|
True,
|
||||||
'Provided as PDF on 1 January at 1:01am',
|
'Provided as PDF today at 1:01am',
|
||||||
'This letter passed our checks, but we will not print it because you used a test key.',
|
'This letter passed our checks, but we will not print it because you used a test key.',
|
||||||
'Postage: second class'
|
'Postage: second class'
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
False,
|
False,
|
||||||
'‘sample template’ was sent on 1 January at 1:01am',
|
'‘sample template’ was sent today at 1:01am',
|
||||||
'We will not print this letter because you used a test key.',
|
'We will not print this letter because you used a test key.',
|
||||||
'Postage: second class',
|
'Postage: second class',
|
||||||
),
|
),
|
||||||
@@ -377,7 +398,7 @@ def test_notification_page_shows_cancelled_or_failed_letter(
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert normalize_spaces(page.select('main p')[0].text) == (
|
assert normalize_spaces(page.select('main p')[0].text) == (
|
||||||
"‘sample template’ was sent by Test User on 1 January at 1:01am"
|
"‘sample template’ was sent by Test User today at 1:01am"
|
||||||
)
|
)
|
||||||
assert normalize_spaces(page.select('main p')[1].text) == (
|
assert normalize_spaces(page.select('main p')[1].text) == (
|
||||||
expected_message
|
expected_message
|
||||||
|
|||||||
Reference in New Issue
Block a user