mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-17 04:59:37 -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):
|
||||
|
||||
Reference in New Issue
Block a user