← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20986: Functionality for calculating date diff in weeks and months in program rules

 

------------------------------------------------------------
revno: 20986
committer: Markus Bekken <markus.bekken@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-11-09 08:37:24 +0100
message:
  Functionality for calculating date diff in weeks and months in program rules
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2015-10-30 15:13:52 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.angular.services.js	2015-11-09 07:37:24 +0000
@@ -1182,6 +1182,8 @@
         //Called from "runExpression". Only proceed with this logic in case there seems to be dhis function calls: "d2:" is present.
         if(angular.isDefined(expression) && expression.indexOf("d2:") !== -1){   
             var dhisFunctions = [{name:"d2:daysBetween",parameters:2},
+                                {name:"d2:weeksBetween",parameters:2},
+                                {name:"d2:monthsBetween",parameters:2},
                                 {name:"d2:yearsBetween",parameters:2},
                                 {name:"d2:floor",parameters:1},
                                 {name:"d2:modulus",parameters:2},
@@ -1236,6 +1238,24 @@
                             expression = expression.replace(callToThisFunction, seconddate.diff(firstdate,'days'));
                             successfulExecution = true;
                         } 
+                        else if(dhisFunction.name === "d2:weeksBetween") {
+                            var firstdate = $filter('trimquotes')(parameters[0]);
+                            var seconddate = $filter('trimquotes')(parameters[1]);
+                            firstdate = moment(firstdate);
+                            seconddate = moment(seconddate);
+                            //Replace the end evaluation of the dhis function:
+                            expression = expression.replace(callToThisFunction, seconddate.diff(firstdate,'weeks'));
+                            successfulExecution = true;
+                        }
+                        else if(dhisFunction.name === "d2:monthsBetween") {
+                            var firstdate = $filter('trimquotes')(parameters[0]);
+                            var seconddate = $filter('trimquotes')(parameters[1]);
+                            firstdate = moment(firstdate);
+                            seconddate = moment(seconddate);
+                            //Replace the end evaluation of the dhis function:
+                            expression = expression.replace(callToThisFunction, seconddate.diff(firstdate,'months'));
+                            successfulExecution = true;
+                        }
                         else if(dhisFunction.name === "d2:yearsBetween") {
                             var firstdate = $filter('trimquotes')(parameters[0]);
                             var seconddate = $filter('trimquotes')(parameters[1]);
@@ -1244,7 +1264,7 @@
                             //Replace the end evaluation of the dhis function:
                             expression = expression.replace(callToThisFunction, seconddate.diff(firstdate,'years'));
                             successfulExecution = true;
-                        } 
+                        }
                         else if(dhisFunction.name === "d2:floor") {
                             var floored = Math.floor(parameters[0]);
                             //Replace the end evaluation of the dhis function: