Fix relative date for returned letters

It was saying ‘16 hours ago’ instead of today. This is because, in
strftime:
- `%M` means minute, not month
- `%D` means short MM/DD/YY date, not day of the month

The test wasn’t catching this because the freeze time and mocked value
from the API were set to the same minute.
This commit is contained in:
Chris Hill-Scott
2020-04-01 17:30:22 +01:00
parent 84e063c901
commit e8b5de533d
2 changed files with 21 additions and 7 deletions

View File

@@ -386,9 +386,9 @@ def format_delta(date):
def format_delta_days(date):
now = datetime.now(timezone.utc)
date = utc_string_to_aware_gmt_datetime(date)
if date.strftime('%Y-%M-%D') == now.strftime('%Y-%M-%D'):
if date.strftime('%Y-%m-%d') == now.strftime('%Y-%m-%d'):
return "today"
if date.strftime('%Y-%M-%D') == (now - timedelta(days=1)).strftime('%Y-%M-%D'):
if date.strftime('%Y-%m-%d') == (now - timedelta(days=1)).strftime('%Y-%m-%d'):
return "yesterday"
return naturaltime_without_indefinite_article(now - date)