=== 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 2015-11-30 03:58:28 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/dhis2.period.js 2016-01-07 11:18:47 +0000 @@ -105,7 +105,7 @@ if (options) { options.altField = '#' + isoFieldId; } - + $el.calendarsPicker($.extend({}, this.defaults, options)); }; @@ -280,10 +280,10 @@ */ dhis2.period.PeriodGenerator.prototype.filterOpenPeriods = function( generator, periods, n ) { var max = this.generators[generator].todayPlusPeriods(n); - + var array = []; var today = this.calendar.today(); - + $.each(periods, function() { if( this['_endDate'].compareTo(max) < 0 ) { array.push(this); @@ -465,7 +465,7 @@ /** * Get the date calculated from current date added the given number of periods * of this period type. - * + * * @param {int} n number of periods. * @return date object. */ @@ -541,7 +541,23 @@ var periods = []; var startDate = this.calendar.newDate(year, 1, 1); - startDate.add(-(startDate.dayOfWeek() - 1), 'd'); // rewind to start of week, might cross year boundary + // startDate.add(-(startDate.dayOfWeek() - 1), 'd'); // rewind to start of week, might cross year boundary + + var day = startDate.dayOfWeek(); + + if( day == 0 ) // Sunday (0), forward to Monday + { + startDate.add(1, 'd'); + } + else if( day <= 4 ) // Monday - Thursday, rewind to Monday + { + startDate.add(( ( day - 1 ) * -1 ), 'd'); + } + else + // Friday - Saturday, forward to Monday + { + startDate.add(8 - day, 'd'); + } // no reliable way to figure out number of weeks in a year (can differ in different calendars) // goes up to 200, but break when week is back to 1 @@ -595,7 +611,7 @@ $generate: function( offset ) { var year = offset + this.calendar.today().year(); var periods = []; - + for( var month = 1; month <= getHMISMonthsInYear(this.calendar, year); month++ ) { var startDate = this.calendar.newDate(year, month, 1); var endDate = this.calendar.newDate(startDate).set(startDate.daysInMonth(month), 'd'); @@ -978,15 +994,15 @@ dhis2.period.FinancialOctoberGenerator.prototype = Object.create(dhis2.period.FinancialBaseGenerator.prototype); /** - * Convenience method to get DHIS2/HMIS months in a year + * Convenience method to get DHIS2/HMIS months in a year */ function getHMISMonthsInYear( calendar, year ) { - + var monthsInYear = calendar.monthsInYear(year); - + if( $.calendars.calendars.ethiopian && calendar instanceof $.calendars.calendars.ethiopian ){ monthsInYear = monthsInYear - 1; } - + return monthsInYear; }