← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15874: bugfix in generateRollingPeriods, don't set month to 1. Also added tests for last 4 weeks.

 

------------------------------------------------------------
revno: 15874
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-06-27 17:28:37 +0700
message:
  bugfix in generateRollingPeriods, don't set month to 1. Also added tests for last 4 weeks.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.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/period/WeeklyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2014-06-23 14:46:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2014-06-27 10:28:37 +0000
@@ -152,7 +152,6 @@
         Calendar cal = getCalendar();
         
         List<Period> periods = Lists.newArrayList();
-        dateUnit.setMonth( 1 );
         dateUnit = cal.minusDays( dateUnit, cal.weekday( dateUnit ) - 1 );
         dateUnit = cal.minusDays( dateUnit, 357 );
 

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java	2014-05-21 11:12:07 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/RelativePeriodTest.java	2014-06-27 10:28:37 +0000
@@ -261,6 +261,27 @@
     }
 
     @Test
+    public void testGetLast4Weeks()
+    {
+        List<Period> relatives = new RelativePeriods().setLast4Weeks( true ).getRelativePeriods( getDate( 2012, 1, 20 ), null, false );
+
+        assertEquals( 4, relatives.size() );
+        assertTrue( relatives.contains( new Period( new WeeklyPeriodType(), getDate( 2012, 1, 16 ), getDate( 2012, 1, 22 ) ) ) );
+        assertTrue( relatives.contains( new Period( new WeeklyPeriodType(), getDate( 2012, 1, 9 ), getDate( 2012, 1, 15 ) ) ) );
+        assertTrue( relatives.contains( new Period( new WeeklyPeriodType(), getDate( 2012, 1, 2 ), getDate( 2012, 1, 8 ) ) ) );
+        assertTrue( relatives.contains( new Period( new WeeklyPeriodType(), getDate( 2011, 12, 26 ), getDate( 2012, 1, 1 ) ) ) );
+
+        relatives = new RelativePeriods().setLast4Weeks( true ).getRelativePeriods( getDate( 2010, 5, 4 ), null, false );
+        System.err.println( "relatives: " + relatives );
+
+        assertEquals( 4, relatives.size() );
+        assertTrue( relatives.contains( new Period( new WeeklyPeriodType(), getDate( 2010, 5, 3 ), getDate( 2010, 5, 9 ) ) ) );
+        assertTrue( relatives.contains( new Period( new WeeklyPeriodType(), getDate( 2010, 4, 26 ), getDate( 2010, 5, 2 ) ) ) );
+        assertTrue( relatives.contains( new Period( new WeeklyPeriodType(), getDate( 2010, 4, 19 ), getDate( 2010, 4, 25 ) ) ) );
+        assertTrue( relatives.contains( new Period( new WeeklyPeriodType(), getDate( 2010, 4, 12 ), getDate( 2010, 4, 18 ) ) ) );
+    }
+
+    @Test
     public void testGetQuartersThisYear()
     {
         List<Period> relatives = new RelativePeriods().setQuartersThisYear( true ).getRelativePeriods( getDate( 2001, 4, 1 ), null, false );