← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15024: yearly js generator

 

------------------------------------------------------------
revno: 15024
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-04-27 20:45:23 +0545
message:
  yearly 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:45:34 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js	2014-04-27 15:00:23 +0000
@@ -30,6 +30,34 @@
 
 dhis2.period.DATE_FORMAT = "yyyy-mm-dd";
 
+dhis2.period.generateYearlyPeriods = function( cal, offset ) {
+  var year = cal.today().year() - offset;
+
+  var periods = [];
+
+  // generate 11 years, thisYear +/- 5 years
+  for( var i = -5; i < 6; i++ ) {
+    var startDate = cal.newDate(year + i, 1, 1);
+    var endDate = cal.newDate(startDate).set(cal.monthsInYear(year + i), 'm');
+    endDate.set(endDate.daysInMonth(endDate.month()), '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("yyyy");
+    period['id'] = 'Yearly_' + period['startDate'];
+    period['iso'] = startDate.formatDate("yyyy");
+
+    periods.push(period);
+  }
+
+  return periods;
+};
+
 dhis2.period.generateMonthlyPeriods = function( cal, offset ) {
   var year = cal.today().year() - offset;