Add years to old dates

Just to disambiguate things without introducing unnecessary noise.
This commit is contained in:
Chris Hill-Scott
2019-10-21 14:14:59 +01:00
parent 600e3affc1
commit a765920f65
3 changed files with 16 additions and 10 deletions

View File

@@ -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)

View File

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

View File

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