--- a/src/pyams_utils/date.py Thu Jun 02 16:39:26 2016 +0200
+++ b/src/pyams_utils/date.py Thu Jun 02 16:40:06 2016 +0200
@@ -94,18 +94,13 @@
return format_date(value, format, request)
-def get_age(value):
- """Get age of a given datetime (including timezone) compared to current datetime (in UTC)
-
- @param value: a datetime value, including timezone
- @type value: datetime
- @return: string representing value age
- @rtype: gettext translated string
- """
- request = check_request()
+def get_age(value, request=None):
+ """Get age of a given datetime (including timezone) compared to current datetime (in UTC)"""
+ if request is None:
+ request = check_request()
translate = request.localizer.translate
now = gmtime(datetime.utcnow())
- delta = now - value
+ delta = now - gmtime(value)
if delta.days > 60:
return translate(_("%d months ago")) % int(round(delta.days * 1.0 / 30))
elif delta.days > 10: