← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15022: add quarterly js generator

 

------------------------------------------------------------
revno: 15022
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-04-27 20:18:19 +0545
message:
  add quarterly js generator
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.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.period.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js	2014-04-27 14:22:44 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js	2014-04-27 14:33:19 +0000
@@ -82,3 +82,31 @@
 
   return periods;
 };
+
+dhis2.period.generateQuarterlyPeriods = function( cal, offset ) {
+  var year = cal.today().year() - offset;
+
+  var periods = [];
+
+  for( var month = 1, idx = 1; month <= cal.monthsInYear(year); month += 3, idx++ ) {
+    log('month: ' + month);
+    var startDate = cal.newDate(year, month, 1);
+    var endDate = cal.newDate(startDate).set(month + 2, 'm');
+    endDate.set(endDate.daysInMonth(month + 2), 'd');
+
+    if( startDate.year() != endDate.year() ) {
+      break;
+    }
+
+    var period = {};
+    period['startDate'] = startDate.formatDate(dhis2.period.DATE_FORMAT);
+    period['endDate'] = endDate.formatDate(dhis2.period.DATE_FORMAT);
+    period['name'] = startDate.formatDate("MM") + '-' + endDate.formatDate('MM') + ' ' + year;
+    period['id'] = 'Monthly_' + period['startDate'];
+    period['iso'] = startDate.formatDate("yyyy") + 'Q' + idx;
+
+    periods.push(period);
+  }
+
+  return periods;
+};