mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-02 23:47:42 -04:00
Say ‘1 hour/month ago’ not ‘an hour/a month ago’
I think it read better without the indefinite article when it’s, for example, placed alongside messages that read ‘2 hours ago’.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import itertools
|
||||
import os
|
||||
import re
|
||||
import urllib
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from functools import partial
|
||||
@@ -338,6 +339,14 @@ def _format_datetime_short(datetime):
|
||||
return datetime.strftime('%d %B').lstrip('0')
|
||||
|
||||
|
||||
def naturaltime_without_indefinite_article(date):
|
||||
return re.sub(
|
||||
'an? (.*) ago',
|
||||
lambda match: '1 {} ago'.format(match.group(1)),
|
||||
humanize.naturaltime(date),
|
||||
)
|
||||
|
||||
|
||||
def format_delta(date):
|
||||
delta = (
|
||||
datetime.now(timezone.utc)
|
||||
@@ -348,7 +357,7 @@ def format_delta(date):
|
||||
return "just now"
|
||||
if delta < timedelta(seconds=60):
|
||||
return "in the last minute"
|
||||
return humanize.naturaltime(delta)
|
||||
return naturaltime_without_indefinite_article(delta)
|
||||
|
||||
|
||||
def format_delta_days(date):
|
||||
@@ -358,7 +367,7 @@ def format_delta_days(date):
|
||||
return "today"
|
||||
if date.strftime('%Y-%M-%D') == (now - timedelta(days=1)).strftime('%Y-%M-%D'):
|
||||
return "yesterday"
|
||||
return humanize.naturaltime(now - date)
|
||||
return naturaltime_without_indefinite_article(now - date)
|
||||
|
||||
|
||||
def valid_phone_number(phone_number):
|
||||
|
||||
@@ -262,9 +262,9 @@ def test_inbound_messages_shows_count_of_messages_when_there_are_no_messages(
|
||||
|
||||
|
||||
@pytest.mark.parametrize('index, expected_row', enumerate([
|
||||
'07900 900000 message-1 an hour ago',
|
||||
'07900 900000 message-2 an hour ago',
|
||||
'07900 900000 message-3 an hour ago',
|
||||
'07900 900000 message-1 1 hour ago',
|
||||
'07900 900000 message-2 1 hour ago',
|
||||
'07900 900000 message-3 1 hour ago',
|
||||
'07900 900002 message-4 3 hours ago',
|
||||
'07900 900004 message-5 5 hours ago',
|
||||
'07900 900006 message-6 7 hours ago',
|
||||
@@ -557,6 +557,9 @@ def test_returned_letters_shows_count_of_recently_returned_letters(
|
||||
('2020-01-25', (
|
||||
'0 returned letters latest report 8 days ago'
|
||||
)),
|
||||
('2020-01-01', (
|
||||
'0 returned letters latest report 1 month ago'
|
||||
)),
|
||||
('2019-09-09', (
|
||||
'0 returned letters latest report 4 months ago'
|
||||
)),
|
||||
|
||||
Reference in New Issue
Block a user