Use "gmtime" in "get_age" function
authorThierry Florac <thierry.florac@onf.fr>
Thu, 02 Jun 2016 16:40:06 +0200
changeset 64 70f2321e267a
parent 63 f188db1a1ce7
child 65 326d216d3fc2
Use "gmtime" in "get_age" function
src/pyams_utils/date.py
--- 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: