From a765920f6571ade405a08cb08f7078f037be5d0b Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 21 Oct 2019 14:14:59 +0100 Subject: [PATCH] Add years to old dates Just to disambiguate things without introducing unnecessary noise. --- app/__init__.py | 10 +++++++--- tests/app/main/views/test_history.py | 12 +++++++----- tests/app/main/views/test_jobs.py | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index fb904e4f6..e040868a2 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -297,12 +297,16 @@ def get_human_day(time): # 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() - if date == (datetime.utcnow() + timedelta(days=1)).date(): + now = datetime.utcnow() + + if date == (now + timedelta(days=1)).date(): return 'tomorrow' - if date == datetime.utcnow().date(): + if date == now.date(): return 'today' - if date == (datetime.utcnow() - timedelta(days=1)).date(): + if date == (now - timedelta(days=1)).date(): return 'yesterday' + if date.strftime('%Y') != now.strftime('%Y'): + return '{} {}'.format(_format_datetime_short(date), date.strftime('%Y')) return _format_datetime_short(date) diff --git a/tests/app/main/views/test_history.py b/tests/app/main/views/test_history.py index 09da2d0a9..8b0e64d13 100644 --- a/tests/app/main/views/test_history.py +++ b/tests/app/main/views/test_history.py @@ -1,4 +1,5 @@ import pytest +from freezegun import freeze_time from tests.conftest import SERVICE_ONE_ID, normalize_spaces @@ -20,14 +21,14 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces ), ), ( - '11 November', + '11 November 2011', ( 'Test User 11:11am ' 'Created an API key called ‘Bad key’' ), ), ( - '10 October', + '10 October 2010', ( 'Test User 11:10am ' 'Created an API key called ‘Good key’ ' @@ -45,14 +46,14 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces ), ), ( - '11 November', + '11 November 2011', ( 'Test User 11:11am ' 'Created an API key called ‘Bad key’' ), ), ( - '10 October', + '10 October 2010', ( 'Test User 11:10am ' 'Created an API key called ‘Good key’' @@ -68,7 +69,7 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces ), ), ( - '10 October', + '10 October 2010', ( 'Unknown 2:01am ' 'Created this service and called it ‘Example service’' @@ -76,6 +77,7 @@ from tests.conftest import SERVICE_ONE_ID, normalize_spaces ), ]), )) +@freeze_time("2012-01-01 01:01:01") def test_history( client_request, mock_get_service_history, diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index 745dccd2f..695e27ae2 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -45,11 +45,11 @@ from tests.conftest import ( ), ( 'send_me_later.csv ' - 'Sending 1 January at 11:09am 1' + 'Sending 1 January 2016 at 11:09am 1' ), ( 'even_later.csv ' - 'Sending 1 January at 11:09pm 1' + 'Sending 1 January 2016 at 11:09pm 1' ), ( 'File Sending Delivered Failed'