[Formed-commits] r375 - trunk/formed/formed/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Jul 29 16:40:04 CEST 2010
Author: torsten
Date: 2010-07-29 16:40:03 +0200 (Thu, 29 Jul 2010)
New Revision: 375
Modified:
trunk/formed/formed/model/exprtree.py
Log:
* formed/formed/model/exprtree.py: Added "days" function.
Modified: trunk/formed/formed/model/exprtree.py
===================================================================
--- trunk/formed/formed/model/exprtree.py 2010-07-29 08:23:51 UTC (rev 374)
+++ trunk/formed/formed/model/exprtree.py 2010-07-29 14:40:03 UTC (rev 375)
@@ -34,7 +34,7 @@
import codecs
import traceback
-from datetime import date
+from datetime import date, timedelta
from types import StringTypes
from formed.model import UNKNOWN_DATE, UNKNOWN_INT, UNKNOWN_STR
@@ -335,6 +335,16 @@
years -= 1
return years
+def DAYS(start, end):
+ """Return the number of days between the dates start and end.
+ This is useful for e.g. age calculations. The order of the dates is
+ irrelevant.
+ """
+ if end < start:
+ start, end = end, start
+ td = end - start
+ return td.days
+
NODE_FACTORIES = {
'+': lambda s: OperatorBinary(s.pop(), s.pop(), ADD),
'-': lambda s: OperatorBinary(s.pop(-2), s.pop(), MINUS),
@@ -360,6 +370,7 @@
'known': lambda s: OperatorUnary(s.pop(), KNOWN),
'type': lambda s: OperatorUnary(s.pop(), TYPE),
'years': lambda s: OperatorBinary(s.pop(), s.pop(), YEARS),
+ 'days': lambda s: OperatorBinary(s.pop(), s.pop(), DAYS),
'and': lambda s: And(s.pop(-2), s.pop()),
'or': lambda s: Or(s.pop(-2), s.pop()),
'today': lambda s: Today(),
More information about the Formed-commits
mailing list