[Mpuls-commits] r4343 - base/trunk/mpulsweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Dec 9 15:09:26 CET 2010


Author: torsten
Date: 2010-12-09 15:09:25 +0100 (Thu, 09 Dec 2010)
New Revision: 4343

Modified:
   base/trunk/mpulsweb/lib/helpers.py
Log:
* mpulsweb/lib/helpers.py (timedelta_in_years), (get_age): 
Issue821: Added new function to calculate timedelta in years and age.


Modified: base/trunk/mpulsweb/lib/helpers.py
===================================================================
--- base/trunk/mpulsweb/lib/helpers.py	2010-12-09 13:36:28 UTC (rev 4342)
+++ base/trunk/mpulsweb/lib/helpers.py	2010-12-09 14:09:25 UTC (rev 4343)
@@ -302,6 +302,19 @@
     return format_number(float(ti.days) / 7.0
                          + ti.seconds / (60.0 * 24.0 * 7.0))
 
+def timedelta_in_years(ti, empty=None, precision=None):
+    if ti is None:
+        return empty
+    return format_number(float(ti.days) / 365.0 
+                         + ti.seconds / (60.0 * 24.0 * 365.0))
+
+def get_age(ti, empty=None):
+    if ti is None:
+        return empty
+    return int(float(ti.days) / 365.0 
+                         + ti.seconds / (60.0 * 24.0 * 365.0))
+
+
 def human_timedelta(td, empty=None):
     if td is None:
         return empty



More information about the Mpuls-commits mailing list