=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAbstractPeriodType.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAbstractPeriodType.java 2014-08-29 10:02:21 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAbstractPeriodType.java 2014-10-15 14:44:21 +0000 @@ -65,12 +65,12 @@ public Period createPeriod( DateTimeUnit dateTimeUnit, Calendar calendar ) { int year = calendar.monthsInYear() * dateTimeUnit.getYear(); - int yearMonth = year + dateTimeUnit.getMonth() - getBaseMonth(); + int yearMonth = year + dateTimeUnit.getMonth() - getBaseMonth() - 1; // TODO how should we handle years with odd number of months? (Ethiopian) int months = (((yearMonth % 12) / 6) * 6) + getBaseMonth(); - + DateTimeUnit start = new DateTimeUnit( dateTimeUnit ); start.setDay( 1 ); start.setMonth( 1 ); === modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java' --- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java 2014-10-14 13:30:08 +0000 +++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java 2014-10-15 14:44:21 +0000 @@ -55,7 +55,7 @@ @Test public void testCreatePeriod() { - testDate = new DateTime( 2009, 8, 15, 0, 0 ); + testDate = new DateTime( 2009, 8, 15, 0, 0 ); startDate = new DateTime( 2009, 7, 1, 0, 0 ); endDate = new DateTime( 2009, 12, 31, 0, 0 ); @@ -65,13 +65,33 @@ assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); - testDate = new DateTime( 2009, 4, 15, 0, 0 ); - - startDate = new DateTime( 2009, 1, 1, 0, 0 ); - endDate = new DateTime( 2009, 6, 30, 0, 0 ); - - period = periodType.createPeriod( testDate.toDate() ); - + testDate = new DateTime( 2009, 4, 15, 0, 0 ); + + startDate = new DateTime( 2009, 1, 1, 0, 0 ); + endDate = new DateTime( 2009, 6, 30, 0, 0 ); + + period = periodType.createPeriod( testDate.toDate() ); + + assertEquals( startDate.toDate(), period.getStartDate() ); + assertEquals( endDate.toDate(), period.getEndDate() ); + + testDate = new DateTime( 2014, 6, 1, 0, 0 ); + + startDate = new DateTime( 2014, 1, 1, 0, 0 ); + endDate = new DateTime( 2014, 6, 30, 0, 0 ); + + period = periodType.createPeriod( testDate.toDate() ); + + assertEquals( startDate.toDate(), period.getStartDate() ); + assertEquals( endDate.toDate(), period.getEndDate() ); + + testDate = new DateTime( 2014, 7, 1, 0, 0 ); + + startDate = new DateTime( 2014, 7, 1, 0, 0 ); + endDate = new DateTime( 2014, 12, 31, 0, 0 ); + + period = periodType.createPeriod( testDate.toDate() ); + assertEquals( startDate.toDate(), period.getStartDate() ); assertEquals( endDate.toDate(), period.getEndDate() ); }