Refactor to use shared date comparison function

This means we don’t have to repeatedly do timezone conversions or string
to datetime conversions in our business logic.
This commit is contained in:
Chris Hill-Scott
2020-09-29 13:17:12 +01:00
parent 86ec9430a2
commit 5c2469b24e
4 changed files with 18 additions and 20 deletions

View File

@@ -820,10 +820,10 @@ def format_thousands(value):
return value
def is_less_than_90_days_ago(date_from_db):
return (datetime.utcnow() - datetime.strptime(
date_from_db, "%Y-%m-%dT%H:%M:%S.%fZ"
)).days < 90
def is_less_than_days_ago(date_from_db, number_of_days):
return (
datetime.utcnow().astimezone(pytz.utc) - parser.parse(date_from_db).astimezone(pytz.utc)
).days < number_of_days
def hide_from_search_engines(f):