← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16372: bugfixes related to bi-monthly period parsing / handling, only allows bi-monthly periods from 1-6...

 

------------------------------------------------------------
revno: 16372
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-08-11 12:27:09 +0700
message:
  bugfixes related to bi-monthly period parsing / handling, only allows bi-monthly periods from 1-6 (start: x*2-1). Also adds more tests for bi-monthly, and updates old wrong tests. Analytics must be re-run to get correct values.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParser.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParserTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java


--
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-api/src/main/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParser.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParser.java	2014-05-23 15:34:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParser.java	2014-08-11 05:27:09 +0000
@@ -155,7 +155,12 @@
             int year = Integer.parseInt( matcher.group( 1 ) );
             int month = Integer.parseInt( matcher.group( 2 ) );
 
-            DateUnit start = new DateUnit( year, month, 1 );
+            if ( month < 1 || month > 6 )
+            {
+                return null;
+            }
+
+            DateUnit start = new DateUnit( year, (month * 2) - 1, 1 );
             DateUnit end = new DateUnit( start );
             end = getCalendar().plusMonths( end, 2 );
             end = getCalendar().minusDays( end, 1 );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java	2014-06-23 14:46:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java	2014-08-11 05:27:09 +0000
@@ -29,7 +29,6 @@
  */
 
 import com.google.common.collect.Lists;
-
 import org.hisp.dhis.calendar.Calendar;
 import org.hisp.dhis.calendar.DateUnit;
 
@@ -90,7 +89,7 @@
     public Period getNextPeriod( Period period )
     {
         Calendar cal = getCalendar();
-        
+
         DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
         dateUnit = cal.plusMonths( dateUnit, 2 );
 
@@ -101,7 +100,7 @@
     public Period getPreviousPeriod( Period period )
     {
         Calendar cal = getCalendar();
-        
+
         DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
         dateUnit = cal.minusMonths( dateUnit, 2 );
 
@@ -116,7 +115,7 @@
     public List<Period> generatePeriods( DateUnit dateUnit )
     {
         Calendar cal = getCalendar();
-        
+
         dateUnit.setMonth( 1 );
         dateUnit.setDay( 1 );
 
@@ -141,7 +140,7 @@
     public List<Period> generateRollingPeriods( DateUnit dateUnit )
     {
         Calendar cal = getCalendar();
-        
+
         dateUnit.setDay( 1 );
         dateUnit = cal.minusMonths( dateUnit, (dateUnit.getMonth() % 2) + 10 );
 
@@ -159,7 +158,7 @@
     @Override
     public String getIsoDate( DateUnit dateUnit )
     {
-        return String.format( "%d%02dB", dateUnit.getYear(), dateUnit.getMonth() );
+        return String.format( "%d%02dB", dateUnit.getYear(), (dateUnit.getMonth() + 1) / 2 );
     }
 
     @Override
@@ -172,7 +171,7 @@
     public Date getRewindedDate( Date date, Integer rewindedPeriods )
     {
         Calendar cal = getCalendar();
-        
+
         date = date != null ? date : new Date();
         rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
 

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParserTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParserTest.java	2014-08-11 05:04:02 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/DateUnitPeriodTypeParserTest.java	2014-08-11 05:27:09 +0000
@@ -67,8 +67,14 @@
         assertEquals( new DateInterval( new DateUnit( 2014, 5, 1 ), new DateUnit( 2014, 5, 31 ) ), format.parse( "2014-05" ) );
 
         // bi-monthly
-        assertEquals( new DateInterval( new DateUnit( 2014, 2, 1 ), new DateUnit( 2014, 3, 31 ) ), format.parse( "201402B" ) );
-        assertEquals( new DateInterval( new DateUnit( 2014, 7, 1 ), new DateUnit( 2014, 8, 31 ) ), format.parse( "201407B" ) );
+        assertNull( format.parse( "201400B" ) );
+        assertNull( format.parse( "201407B" ) );
+        assertEquals( new DateInterval( new DateUnit( 2014, 1, 1 ), new DateUnit( 2014, 2, 28 ) ), format.parse( "201401B" ) );
+        assertEquals( new DateInterval( new DateUnit( 2014, 3, 1 ), new DateUnit( 2014, 4, 30 ) ), format.parse( "201402B" ) );
+        assertEquals( new DateInterval( new DateUnit( 2014, 5, 1 ), new DateUnit( 2014, 6, 30 ) ), format.parse( "201403B" ) );
+        assertEquals( new DateInterval( new DateUnit( 2014, 7, 1 ), new DateUnit( 2014, 8, 31 ) ), format.parse( "201404B" ) );
+        assertEquals( new DateInterval( new DateUnit( 2014, 9, 1 ), new DateUnit( 2014, 10, 31 ) ), format.parse( "201405B" ) );
+        assertEquals( new DateInterval( new DateUnit( 2014, 11, 1 ), new DateUnit( 2014, 12, 31 ) ), format.parse( "201406B" ) );
 
         // quarter
         assertNull( format.parse( "2014Q0" ) );

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/StringFormatTest.java	2014-08-11 05:27:09 +0000
@@ -74,7 +74,7 @@
         assertEquals( "Quarter format", "2010Q1", quarter1.getIsoDate() );
         assertEquals( "Semester format", "2010S1", semester1.getIsoDate() );
         assertEquals( "SemesterApril format", "2010AprilS1", semesterApril1.getIsoDate() );
-        assertEquals( "Bimonth format", "201003B", biMonth1.getIsoDate() );
+        assertEquals( "Bimonth format", "201002B", biMonth1.getIsoDate() );
         assertEquals( "Financial April", "2010April", financialApril.getIsoDate() );
         assertEquals( "Financial July", "2010July", financialJuly.getIsoDate() );
         assertEquals( "Financial Oct", "2010Oct", financialOct.getIsoDate() );
@@ -85,7 +85,7 @@
         assertEquals( quarter1, PeriodType.getPeriodFromIsoString( "2010Q1" ) );
         assertEquals( semester1, PeriodType.getPeriodFromIsoString( "2010S1" ) );
         assertEquals( semesterApril1, PeriodType.getPeriodFromIsoString( "2010AprilS1" ) );
-        assertEquals( biMonth1, PeriodType.getPeriodFromIsoString( "201003B" ) );
+        assertEquals( biMonth1, PeriodType.getPeriodFromIsoString( "201002B" ) );
         assertEquals( financialApril, PeriodType.getPeriodFromIsoString( "2010April" ) );
         assertEquals( financialJuly, PeriodType.getPeriodFromIsoString( "2010July" ) );
         assertEquals( financialOct, PeriodType.getPeriodFromIsoString( "2010Oct" ) );