Skip to content

Commit

Permalink
Add one quarter from next year if the current is the last quarter of …
Browse files Browse the repository at this point in the history
…the year
  • Loading branch information
Markionium committed Mar 16, 2015
1 parent 6a75c32 commit b56550c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/period/period-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,21 @@ function periodService(d2Api) {

//Show this years and last years quarters
if (/^Quarterly$/.test(currentPeriodType)) {
var futureYear = [];
var thisYear = dhis2.period.generator.generateReversedPeriods(currentPeriodType, 0);

var currentQuarter = dhis2.period.generator.filterFuturePeriodsExceptCurrent(thisYear);
thisYear = thisYear.slice((3 - currentQuarter.length >= 0) ? 3 - currentQuarter.length : 0);

if (currentQuarter.length === 4) {
futureYear = dhis2.period.generator.generateReversedPeriods(currentPeriodType, 1)[3];
}

var oneYearAgo = dhis2.period.generator.generateReversedPeriods(currentPeriodType, -1);
var twoYearsAgo = dhis2.period.generator.generateReversedPeriods(currentPeriodType, -2);
var threeYearsAgo = dhis2.period.generator.generateReversedPeriods(currentPeriodType, -3);

generatedPeriods = thisYear.concat(oneYearAgo).concat(twoYearsAgo).concat(threeYearsAgo);
generatedPeriods = futureYear.concat(thisYear).concat(oneYearAgo).concat(twoYearsAgo).concat(threeYearsAgo);
return;
}

Expand Down

0 comments on commit b56550c

Please sign in to comment.