← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2912: Simplified implementation of PeriodType.generatePeriods methods. Improved test coverage. Fixed a ...

 

------------------------------------------------------------
revno: 2912
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-02-24 22:01:47 +0100
message:
  Simplified implementation of PeriodType.generatePeriods methods. Improved test coverage. Fixed a few bugs with FinancialAprilPeriodType impl.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/OnChangePeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialAprilPeriodTypeTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/QuarterlyPeriodTypeTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/YearlyPeriodTypeTest.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/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2011-02-01 08:11:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java	2011-02-24 21:01:47 +0000
@@ -38,7 +38,7 @@
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.period.TwoYearlyPeriodType;
+import org.hisp.dhis.period.YearlyPeriodType;
 
 /**
  * A DataElement is a definition (meta-information about) of the entities that
@@ -256,7 +256,7 @@
     {
         PeriodType periodType = getPeriodType();
         
-        return periodType != null ? periodType.getFrequencyOrder() : TwoYearlyPeriodType.FREQUENCY_ORDER;
+        return periodType != null ? periodType.getFrequencyOrder() : YearlyPeriodType.FREQUENCY_ORDER;
     }
 
     /**

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Cal.java	2011-02-24 21:01:47 +0000
@@ -0,0 +1,59 @@
+package org.hisp.dhis.period;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+public class Cal
+{
+    private Calendar calendar;
+    
+    public Cal()
+    {
+        calendar = new GregorianCalendar();
+        calendar.clear();
+    }
+
+    /**
+    * @param year the year starting at AD 1.
+    * @param month the month starting at 1.
+    * @param day the day of the month starting at 1.
+    */
+    public Cal( int year, int month, int day )
+    {
+        calendar = new GregorianCalendar();
+        calendar.clear();
+        set( year, month, day );
+    }
+
+    /**
+     * Returns the value of the given calendar field.
+     * 
+     * @param field the field.
+     */
+    public int get( int field )
+    {
+        return calendar.get( field );
+    }
+    
+    /**
+     * Sets the current time.
+     * 
+     * @param year the year starting at AD 1.
+     * @param month the month starting at 1.
+     * @param day the day of the month starting at 1.
+     */
+    public Cal set( int year, int month, int day )
+    {
+        calendar.set( year, month - 1, day );
+        return this;
+    }
+    
+    /**
+     * Returns the current date the cal.
+     */
+    public Date time()
+    {
+        return calendar.getTime();
+    }
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java	2011-02-16 17:16:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java	2011-02-24 21:01:47 +0000
@@ -122,34 +122,29 @@
         cal.set( Calendar.DAY_OF_YEAR, 1 );
 
         int year = cal.get( Calendar.YEAR );
-
-        ArrayList<Period> days = new ArrayList<Period>();
+        ArrayList<Period> periods = new ArrayList<Period>();
 
         while ( cal.get( Calendar.YEAR ) == year )
         {
-            Date startDate = cal.getTime();
-
-            days.add( new Period( this, startDate, startDate ) );
+            periods.add( createPeriod( cal.getTime() ) );
             cal.add( Calendar.DAY_OF_YEAR, 1 );
         }
 
-        return days;
+        return periods;
     }
 
     @Override
     public String getIsoDate( Period period )
     {
-        SimpleDateFormat format = new SimpleDateFormat(ISO_FORMAT);
-        return format.format( period.getStartDate());
+        return new SimpleDateFormat( ISO_FORMAT ).format( period.getStartDate() );
     }
 
     @Override
     public Period createPeriod( String isoDate )
     {
-        SimpleDateFormat format = new SimpleDateFormat(ISO_FORMAT);
         try
         {
-            Date date = format.parse( isoDate );
+            Date date = new SimpleDateFormat( ISO_FORMAT ).parse( isoDate );
             return createPeriod( date );
         }
         catch ( ParseException e )
@@ -163,6 +158,4 @@
     {
         return ISO_FORMAT;
     }
-    
-    
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java	2011-02-24 21:01:47 +0000
@@ -114,29 +114,28 @@
     }
 
     /**
-     * Generates FinancialAprilPeriods for the last 5, current and next 5 years.
+     * Generates YearlyPeriods for the last 5, current and next 5 years.
      */
     @Override
     public List<Period> generatePeriods( Date date )
     {
-        ArrayList<Period> years = new ArrayList<Period>();
-
         Calendar cal = createCalendarInstance( date );
-        cal.set( Calendar.YEAR, cal.get( Calendar.YEAR ) + cal.get( Calendar.MONDAY ) / 7 - 11);
-        cal.set( Calendar.DAY_OF_YEAR, cal.getActualMinimum( Calendar.DAY_OF_YEAR ) + 90 );
+        
+        boolean past = cal.get( Calendar.MONTH ) >= BASE_MONTH;
+        
+        cal.add( Calendar.YEAR, past ? -5 : -6 );
+        cal.set( Calendar.MONTH, BASE_MONTH );
+        cal.set( Calendar.DATE, 1 );
+
+        ArrayList<Period> periods = new ArrayList<Period>();
 
         for ( int i = 0; i < 11; ++i )
         {
-            Date startDate = cal.getTime();
-
-            cal.add( Calendar.DAY_OF_YEAR, -1 );
+            periods.add( createPeriod( cal ) );
             cal.add( Calendar.YEAR, 1 );
-            years.add( new Period( this, startDate, cal.getTime() ) );
-
-            cal.add( Calendar.DAY_OF_YEAR, 1 );
         }
 
-        return years;
+        return periods;
     }
 
     @Override

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java	2011-02-24 21:01:47 +0000
@@ -45,7 +45,6 @@
 public class MonthlyPeriodType
     extends CalendarPeriodType
 {
-
     private static final String ISO_FORMAT = "yyyyMM";
 
     /**
@@ -79,11 +78,9 @@
     private Period createPeriod( Calendar cal )
     {
         cal.set( Calendar.DAY_OF_MONTH, 1 );
-
         Date startDate = cal.getTime();
-
         cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
-
+        
         return new Period( this, startDate, cal.getTime() );
     }
 
@@ -123,35 +120,30 @@
         Calendar cal = createCalendarInstance( date );
         cal.set( Calendar.DAY_OF_YEAR, 1 );
 
-        int year = cal.get( Calendar.YEAR );
-
-        ArrayList<Period> months = new ArrayList<Period>();
+        int year = cal.get( Calendar.YEAR );        
+        ArrayList<Period> periods = new ArrayList<Period>();
 
         while ( cal.get( Calendar.YEAR ) == year )
         {
-            Date startDate = cal.getTime();
-            cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
-            months.add( new Period( this, startDate, cal.getTime() ) );
-            cal.add( Calendar.DAY_OF_YEAR, 1 );
+            periods.add( createPeriod( cal ) );
+            cal.add( Calendar.MONTH, 1 );
         }
 
-        return months;
+        return periods;
     }
 
     @Override
     public String getIsoDate( Period period )
     {
-        SimpleDateFormat format = new SimpleDateFormat( ISO_FORMAT );
-        return format.format( period.getStartDate() );
+        return new SimpleDateFormat( ISO_FORMAT ).format( period.getStartDate() );
     }
 
     @Override
     public Period createPeriod( String isoDate )
     {
-        SimpleDateFormat format = new SimpleDateFormat( ISO_FORMAT );
         try
         {
-            Date date = format.parse( isoDate );
+            Date date = new SimpleDateFormat( ISO_FORMAT ).parse( isoDate );
             return createPeriod(date);
         }
         catch ( ParseException e )
@@ -165,5 +157,4 @@
     {
         return ISO_FORMAT;
     }
-
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/OnChangePeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/OnChangePeriodType.java	2011-02-15 06:22:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/OnChangePeriodType.java	2011-02-24 21:01:47 +0000
@@ -71,10 +71,8 @@
     private Period createPeriod( Calendar cal )
     {
         Date startDate = cal.getTime();
-
         cal.set( Calendar.YEAR, INSURMOUNTABLE_YEAR );
         cal.set( Calendar.DAY_OF_YEAR, cal.getActualMaximum( Calendar.DAY_OF_YEAR ) );
-
         return new Period( this, startDate, cal.getTime() );
     }
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2011-02-08 13:15:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java	2011-02-24 21:01:47 +0000
@@ -141,7 +141,7 @@
      */
     public int frequencyOrder()
     {
-        return periodType != null ? periodType.getFrequencyOrder() : TwoYearlyPeriodType.FREQUENCY_ORDER;
+        return periodType != null ? periodType.getFrequencyOrder() : YearlyPeriodType.FREQUENCY_ORDER;
     }
 
     /**

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2011-02-15 06:22:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2011-02-24 21:01:47 +0000
@@ -62,7 +62,6 @@
         periodTypes.add( new QuarterlyPeriodType() );
         periodTypes.add( new SixMonthlyPeriodType() );
         periodTypes.add( new YearlyPeriodType() );
-        periodTypes.add( new TwoYearlyPeriodType() );
         periodTypes.add( new FinancialAprilPeriodType() );
         //periodTypes.add( new OnChangePeriodType() );
         //periodTypes.add( new SurveyPeriodType() );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java	2011-02-24 21:01:47 +0000
@@ -122,19 +122,15 @@
         cal.set( Calendar.DAY_OF_YEAR, 1 );
 
         int year = cal.get( Calendar.YEAR );
-
-        ArrayList<Period> quarters = new ArrayList<Period>();
+        ArrayList<Period> periods = new ArrayList<Period>();
 
         while ( cal.get( Calendar.YEAR ) == year )
         {
-            Date startDate = cal.getTime();
-            cal.add( Calendar.MONTH, 2 );
-            cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
-            quarters.add( new Period( this, startDate, cal.getTime() ) );
-            cal.add( Calendar.DAY_OF_YEAR, 1 );
+            periods.add( createPeriod( cal ) );
+            cal.add( Calendar.MONTH, 3 );
         }
 
-        return quarters;
+        return periods;
     }
 
     @Override
@@ -195,8 +191,6 @@
             default:
                 throw new IllegalArgumentException( "Not a valid quarterly starting month" );
             }
-
         }
     }
-
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java	2011-02-24 21:01:47 +0000
@@ -122,19 +122,15 @@
         cal.set( Calendar.DAY_OF_YEAR, 1 );
 
         int year = cal.get( Calendar.YEAR );
-
-        ArrayList<Period> sixMonths = new ArrayList<Period>();
+        ArrayList<Period> periods = new ArrayList<Period>();
 
         while ( cal.get( Calendar.YEAR ) == year )
         {
-            Date startDate = cal.getTime();
-            cal.add( Calendar.MONTH, 5 );
-            cal.set( Calendar.DAY_OF_MONTH, cal.getActualMaximum( Calendar.DAY_OF_MONTH ) );
-            sixMonths.add( new Period( this, startDate, cal.getTime() ) );
-            cal.add( Calendar.DAY_OF_YEAR, 1 );
+            periods.add( createPeriod( cal ) );
+            cal.add( Calendar.MONTH, 6 );
         }
 
-        return sixMonths;
+        return periods;
     }
 
     @Override
@@ -156,7 +152,6 @@
         Calendar cal = createCalendarInstance();
         cal.set( year, month, 1 );
         return createPeriod( cal );
-
     }
 
     @Override
@@ -192,8 +187,6 @@
             default:
                 throw new IllegalArgumentException( "Not a valid six-monthly starting month" );
             }
-
         }
     }
-
 }

=== 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	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2011-02-24 21:01:47 +0000
@@ -75,14 +75,10 @@
     private Period createPeriod( Calendar cal )
     {    	
         cal.set( Calendar.DAY_OF_WEEK, Calendar.MONDAY );
-
         Date startDate = cal.getTime();
-
         cal.add( Calendar.DAY_OF_YEAR, 6 );
-
         return new Period( this, startDate, cal.getTime() );
     }
- 
 
     @Override
     public int getFrequencyOrder()
@@ -214,7 +210,6 @@
         cal.setFirstDayOfWeek( Calendar.MONDAY );
 
         return createPeriod( cal.getTime() );
-
     }
 
     @Override
@@ -222,5 +217,4 @@
     {
         return "yyyyWn (n: week number)";
     }
-
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2011-02-24 21:01:47 +0000
@@ -73,10 +73,8 @@
 
     private Period createPeriod( Calendar cal )
     {
-        cal.set( Calendar.DAY_OF_YEAR, 1 );
-
+        cal.set( Calendar.DAY_OF_YEAR, 1 );        
         Date startDate = cal.getTime();
-
         cal.set( Calendar.DAY_OF_YEAR, cal.getActualMaximum( Calendar.DAY_OF_YEAR ) );
 
         return new Period( this, startDate, cal.getTime() );
@@ -118,17 +116,15 @@
         cal.add( Calendar.YEAR, -5 );
         cal.set( Calendar.DAY_OF_YEAR, 1 );
 
-        ArrayList<Period> years = new ArrayList<Period>();
+        ArrayList<Period> periods = new ArrayList<Period>();
 
         for ( int i = 0; i < 11; ++i )
         {
-            Date startDate = cal.getTime();
-            cal.set( Calendar.DAY_OF_YEAR, cal.getActualMaximum( Calendar.DAY_OF_YEAR ) );
-            years.add( new Period( this, startDate, cal.getTime() ) );
-            cal.add( Calendar.DAY_OF_YEAR, 1 );
+            periods.add( createPeriod( cal ) );
+            cal.add( Calendar.YEAR, 1 );
         }
 
-        return years;
+        return periods;
     }
 
     @Override
@@ -136,10 +132,7 @@
     {
         Calendar cal = createCalendarInstance( period.getStartDate() );
         int year = cal.get( Calendar.YEAR );
-
-        String periodString = String.valueOf( year );
-
-        return periodString;
+        return String.valueOf( year );
     }
 
     @Override
@@ -155,5 +148,4 @@
     {
         return "yyyy";
     }
-
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialAprilPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialAprilPeriodTypeTest.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialAprilPeriodTypeTest.java	2011-02-24 21:01:47 +0000
@@ -29,9 +29,9 @@
 
 import static junit.framework.Assert.assertEquals;
 
-import java.util.Calendar;
 import java.util.List;
 
+import org.hisp.dhis.period.Cal;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -40,97 +40,101 @@
  */
 public class FinancialAprilPeriodTypeTest
 {
-    private Calendar startCal;
-    private Calendar endCal;
-    private Calendar testCal;
+    private Cal startCal;
+    private Cal endCal;
+    private Cal testCal;
     private CalendarPeriodType periodType;
     
     @Before
     public void before()
     {
-        startCal = PeriodType.createCalendarInstance();
-        endCal = PeriodType.createCalendarInstance();
-        testCal = PeriodType.createCalendarInstance();
+        startCal = new Cal();
+        endCal = new Cal();
+        testCal = new Cal();
         periodType = new FinancialAprilPeriodType();
     }
     
     @Test
     public void testCreatePeriod()
     {
-        testCal.set( 2009, Calendar.FEBRUARY, 15 );
-
-        startCal.set( 2008, Calendar.APRIL, 1 );
-        endCal.set( 2009, Calendar.MARCH, 31 );
-        
-        Period period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
-        
-        testCal.set( 2009, Calendar.SEPTEMBER, 12 );
-
-        period = periodType.createPeriod( testCal.getTime() );
-
-        startCal.set( 2009, Calendar.APRIL, 1 );
-        endCal.set( 2010, Calendar.MARCH , 31 );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        testCal.set( 2009, 2, 15 );
+
+        startCal.set( 2008, 4, 1 );
+        endCal.set( 2009, 3, 31 );
+        
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+        
+        testCal.set( 2009, 9, 12 );
+
+        period = periodType.createPeriod( testCal.time() );
+
+        startCal.set( 2009, 4, 1 );
+        endCal.set( 2010, 3, 31 );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
 
     @Test
     public void testGetNextPeriod()
     {
-        testCal.set( 2009, Calendar.FEBRUARY, 15 );
+        testCal.set( 2009, 2, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getNextPeriod( period );
 
-        startCal.set( 2009, Calendar.APRIL, 1 );
-        endCal.set( 2010, Calendar.MARCH, 31 );
+        startCal.set( 2009, 4, 1 );
+        endCal.set( 2010, 3, 31 );
         
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
 
     @Test
     public void testGetPreviousPeriod()
     {
-        testCal.set( 2009, Calendar.FEBRUARY, 15 );
+        testCal.set( 2009, 2, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getPreviousPeriod( period );
 
-        startCal.set( 2007, Calendar.APRIL, 1 );
-        endCal.set( 2008, Calendar.MARCH, 31 );
+        startCal.set( 2007, 4, 1 );
+        endCal.set( 2008, 3, 31 );
         
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
 
     @Test
     public void testGeneratePeriods()
     {
-        testCal.set( 2009, 1, 15 );
-        
-        List<Period> periods = periodType.generatePeriods( testCal.getTime() );
-        
-        startCal.set( 1998, Calendar.APRIL, 1 );
-        endCal.set( 1999, Calendar.MARCH, 31 );
-        
-        Period startPeriod = periods.get( 0 );
-        assertEquals( startCal.getTime(), startPeriod.getStartDate() );
-        assertEquals( endCal.getTime(), startPeriod.getEndDate() );
-        
-        startCal = PeriodType.createCalendarInstance();
-        startCal.set( 2008, Calendar.APRIL, 1 );
-        endCal = PeriodType.createCalendarInstance();
-        endCal.set( 2009, Calendar.MARCH, 31 );
-        
-        Period endPeriod = periods.get( periods.size() - 1 );
-        assertEquals( startCal.getTime(), endPeriod.getStartDate() );
-        assertEquals( endCal.getTime(), endPeriod.getEndDate() );
+        testCal.set( 2009, 2, 15 );
+        
+        List<Period> periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 11, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2003, 4, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2004, 4, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 4, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2006, 4, 1 ).time() ), periods.get( 3 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2007, 4, 1 ).time() ), periods.get( 4 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2008, 4, 1 ).time() ), periods.get( 5 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 4, 1 ).time() ), periods.get( 6 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2010, 4, 1 ).time() ), periods.get( 7 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2011, 4, 1 ).time() ), periods.get( 8 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2012, 4, 1 ).time() ), periods.get( 9 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2013, 4, 1 ).time() ), periods.get( 10 ) );
+        
+        testCal.set( 2009, 9, 12 );
+        
+        periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 11, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2004, 4, 1 ).time() ), periods.get( 0 ) );
     }
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java	2011-02-24 21:01:47 +0000
@@ -28,8 +28,9 @@
 
 import static junit.framework.Assert.assertEquals;
 
-import java.util.Calendar;
+import java.util.List;
 
+import org.hisp.dhis.period.Cal;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -38,73 +39,95 @@
  */
 public class MonthlyPeriodTypeTest
 {
-    private Calendar startCal;
-    private Calendar endCal;
-    private Calendar testCal;
+    private Cal startCal;
+    private Cal endCal;
+    private Cal testCal;
     private CalendarPeriodType periodType;
     
     @Before
     public void before()
     {
-        startCal = PeriodType.createCalendarInstance();
-        endCal = PeriodType.createCalendarInstance();
-        testCal = PeriodType.createCalendarInstance();
+        startCal = new Cal();
+        endCal = new Cal();
+        testCal = new Cal();
         periodType = new MonthlyPeriodType();
     }
     
     @Test
     public void testCreatePeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
-        
-        startCal.set( 2009, Calendar.AUGUST, 1 );
-        endCal.set( 2009, Calendar.AUGUST, 31 );
-
-        Period period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
-        
-        testCal.set( 2009, Calendar.JUNE, 15 );
-        
-        startCal.set( 2009, Calendar.JUNE, 1 );
-        endCal.set( 2009, Calendar.JUNE, 30 );
-
-        period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        testCal.set( 2009, 8, 15 );
+        
+        startCal.set( 2009, 8, 1 );
+        endCal.set( 2009, 8, 31 );
+
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+        
+        testCal.set( 2009, 6, 15 );
+        
+        startCal.set( 2009, 6, 1 );
+        endCal.set( 2009, 6, 30 );
+
+        period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
 
     @Test
     public void testGetNextPeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
+        testCal.set( 2009, 8, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getNextPeriod( period );
 
-        startCal.set( 2009, Calendar.SEPTEMBER, 1 );
-        endCal.set( 2009, Calendar.SEPTEMBER, 30 );
+        startCal.set( 2009, 9, 1 );
+        endCal.set( 2009, 9, 30 );
 
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
     
     @Test
     public void testGetPreviousPeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
+        testCal.set( 2009, 8, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getPreviousPeriod( period );
 
-        startCal.set( 2009, Calendar.JULY, 1 );
-        endCal.set( 2009, Calendar.JULY, 31 );
+        startCal.set( 2009, 7, 1 );
+        endCal.set( 2009, 7, 31 );
 
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+    
+    @Test
+    public void testGeneratePeriods()
+    {
+        testCal.set( 2009, 8, 15 );
+        
+        List<Period> periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 12, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 1, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 2, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 3, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 4, 1 ).time() ), periods.get( 3 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 5, 1 ).time() ), periods.get( 4 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 6, 1 ).time() ), periods.get( 5 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 7, 1 ).time() ), periods.get( 6 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 8, 1 ).time() ), periods.get( 7 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 9, 1 ).time() ), periods.get( 8 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 10, 1 ).time() ), periods.get( 9 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 11, 1 ).time() ), periods.get( 10 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 12, 1 ).time() ), periods.get( 11 ) );
     }
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/QuarterlyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/QuarterlyPeriodTypeTest.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/QuarterlyPeriodTypeTest.java	2011-02-24 21:01:47 +0000
@@ -29,8 +29,9 @@
 
 import static junit.framework.Assert.assertEquals;
 
-import java.util.Calendar;
+import java.util.List;
 
+import org.hisp.dhis.period.Cal;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -39,73 +40,87 @@
  */
 public class QuarterlyPeriodTypeTest
 {
-    private Calendar startCal;
-    private Calendar endCal;
-    private Calendar testCal;
+    private Cal startCal;
+    private Cal endCal;
+    private Cal testCal;
     private CalendarPeriodType periodType;
     
     @Before
     public void before()
     {
-        startCal = PeriodType.createCalendarInstance();
-        endCal = PeriodType.createCalendarInstance();
-        testCal = PeriodType.createCalendarInstance();
+        startCal = new Cal();
+        endCal = new Cal();
+        testCal = new Cal();
         periodType = new QuarterlyPeriodType();
     }
     
     @Test
     public void testCreatePeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
-        
-        startCal.set( 2009, Calendar.JULY, 1 );
-        endCal.set( 2009, Calendar.SEPTEMBER, 30 );
-
-        Period period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
-        
-        testCal.set( 2009, Calendar.APRIL, 15 );
-        
-        startCal.set( 2009, Calendar.APRIL, 1 );
-        endCal.set( 2009, Calendar.JUNE, 30 );
-
-        period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        testCal.set( 2009, 8, 15 );
+        
+        startCal.set( 2009, 7, 1 );
+        endCal.set( 2009, 9, 30 );
+
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+        
+        testCal.set( 2009, 4, 15 );
+        
+        startCal.set( 2009, 4, 1 );
+        endCal.set( 2009, 6, 30 );
+
+        period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
 
     @Test
     public void testGetNextPeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
+        testCal.set( 2009, 8, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getNextPeriod( period );
 
-        startCal.set( 2009, Calendar.OCTOBER, 1 );
-        endCal.set( 2009, Calendar.DECEMBER, 31 );
+        startCal.set( 2009, 10, 1 );
+        endCal.set( 2009, 12, 31 );
 
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
     
     @Test
     public void testGetPreviousPeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
+        testCal.set( 2009, 8, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getPreviousPeriod( period );
 
-        startCal.set( 2009, Calendar.APRIL, 1 );
-        endCal.set( 2009, Calendar.JUNE, 30 );
+        startCal.set( 2009, 4, 1 );
+        endCal.set( 2009, 6, 30 );
 
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+    
+    @Test
+    public void testGeneratePeriods()
+    {
+        testCal.set( 2009, 8, 15 );
+        
+        List<Period> periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 4, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 1, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 4, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 7, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 10, 1 ).time() ), periods.get( 3 ) );
     }
 }

=== 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	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/SixMonthlyPeriodTypeTest.java	2011-02-24 21:01:47 +0000
@@ -30,7 +30,9 @@
 import static junit.framework.Assert.assertEquals;
 
 import java.util.Calendar;
+import java.util.List;
 
+import org.hisp.dhis.period.Cal;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -39,42 +41,42 @@
  */
 public class SixMonthlyPeriodTypeTest
 {
-    private Calendar startCal;
-    private Calendar endCal;
-    private Calendar testCal;
+    private Cal startCal;
+    private Cal endCal;
+    private Cal testCal;
     private CalendarPeriodType periodType;
     
     @Before
     public void before()
     {
-        startCal = PeriodType.createCalendarInstance();
-        endCal = PeriodType.createCalendarInstance();
-        testCal = PeriodType.createCalendarInstance();
+        startCal = new Cal();
+        endCal = new Cal();
+        testCal = new Cal();
         periodType = new SixMonthlyPeriodType();
     }
     
     @Test
     public void testCreatePeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
-        
-        startCal.set( 2009, Calendar.JULY, 1 );
-        endCal.set( 2009, Calendar.DECEMBER, 31 );
-
-        Period period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
-        
-        testCal.set( 2009, Calendar.APRIL, 15 );
-        
-        startCal.set( 2009, Calendar.JANUARY, 1 );
-        endCal.set( 2009, Calendar.JUNE, 30 );
-
-        period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        testCal.set( 2009, 8, 15 );
+        
+        startCal.set( 2009, 7, 1 );
+        endCal.set( 2009, 12, 31 );
+
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+        
+        testCal.set( 2009, 4, 15 );
+        
+        startCal.set( 2009, 1, 1 );
+        endCal.set( 2009, 6, 30 );
+
+        period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
 
     @Test
@@ -82,30 +84,42 @@
     {
         testCal.set( 2009, Calendar.AUGUST, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getNextPeriod( period );
 
-        startCal.set( 2010, Calendar.JANUARY, 1 );
-        endCal.set( 2010, Calendar.JUNE, 30 );
+        startCal.set( 2010, 1, 1 );
+        endCal.set( 2010, 6, 30 );
 
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
     
     @Test
     public void testGetPreviousPeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
+        testCal.set( 2009, 8, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getPreviousPeriod( period );
 
-        startCal.set( 2009, Calendar.JANUARY, 1 );
-        endCal.set( 2009, Calendar.JUNE, 30 );
+        startCal.set( 2009, 1, 1 );
+        endCal.set( 2009, 6, 30 );
 
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+    
+    @Test
+    public void testGeneratePeriods()
+    {
+        testCal.set( 2009, 8, 15 );
+        
+        List<Period> periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 2, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 1, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 7, 1 ).time() ), periods.get( 1 ) );
     }
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/YearlyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/YearlyPeriodTypeTest.java	2011-02-24 18:52:47 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/YearlyPeriodTypeTest.java	2011-02-24 21:01:47 +0000
@@ -29,8 +29,9 @@
 
 import static junit.framework.Assert.assertEquals;
 
-import java.util.Calendar;
+import java.util.List;
 
+import org.hisp.dhis.period.Cal;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -39,70 +40,91 @@
  */
 public class YearlyPeriodTypeTest
 {
-    private Calendar startCal;
-    private Calendar endCal;
-    private Calendar testCal;
+    private Cal startCal;
+    private Cal endCal;
+    private Cal testCal;
     private CalendarPeriodType periodType;
     
     @Before
     public void before()
     {
-        startCal = PeriodType.createCalendarInstance();
-        endCal = PeriodType.createCalendarInstance();
-        testCal = PeriodType.createCalendarInstance();
+        startCal = new Cal();
+        endCal = new Cal();
+        testCal = new Cal();
         periodType = new YearlyPeriodType();
     }
     
     @Test
     public void testCreatePeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
+        testCal.set( 2009, 8, 15 );
         
-        startCal.set( 2009, Calendar.JANUARY, 1 );
-        endCal.set( 2009, Calendar.DECEMBER, 31 );
+        startCal.set( 2009, 1, 1 );
+        endCal.set( 2009, 12, 31 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
-        
-        testCal.set( 2009, Calendar.APRIL, 15 );
-        
-        period = periodType.createPeriod( testCal.getTime() );
-        
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        Period period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+        
+        testCal.set( 2009, 4, 15 );
+        
+        period = periodType.createPeriod( testCal.time() );
+        
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
 
     @Test
     public void testGetNextPeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
+        testCal.set( 2009, 8, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getNextPeriod( period );
 
-        startCal.set( 2010, Calendar.JANUARY, 1 );
-        endCal.set( 2010, Calendar.DECEMBER, 31 );
+        startCal.set( 2010, 1, 1 );
+        endCal.set( 2010, 12, 31 );
 
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
     }
     
     @Test
     public void testGetPreviousPeriod()
     {
-        testCal.set( 2009, Calendar.AUGUST, 15 );
+        testCal.set( 2009, 8, 15 );
 
-        Period period = periodType.createPeriod( testCal.getTime() );
+        Period period = periodType.createPeriod( testCal.time() );
         
         period = periodType.getPreviousPeriod( period );
 
-        startCal.set( 2008, Calendar.JANUARY, 1 );
-        endCal.set( 2008, Calendar.DECEMBER, 31 );
+        startCal.set( 2008, 1, 1 );
+        endCal.set( 2008, 12, 31 );
 
-        assertEquals( startCal.getTime(), period.getStartDate() );
-        assertEquals( endCal.getTime(), period.getEndDate() );
+        assertEquals( startCal.time(), period.getStartDate() );
+        assertEquals( endCal.time(), period.getEndDate() );
+    }
+    
+    @Test
+    public void testGeneratePeriods()
+    {
+        testCal.set( 2009, 8, 15 );
+        
+        List<Period> periods = periodType.generatePeriods( testCal.time() );
+        
+        assertEquals( 11, periods.size() );
+        assertEquals( periodType.createPeriod( new Cal( 2004, 1, 1 ).time() ), periods.get( 0 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2005, 1, 1 ).time() ), periods.get( 1 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2006, 1, 1 ).time() ), periods.get( 2 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2007, 1, 1 ).time() ), periods.get( 3 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2008, 1, 1 ).time() ), periods.get( 4 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2009, 1, 1 ).time() ), periods.get( 5 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2010, 1, 1 ).time() ), periods.get( 6 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2011, 1, 1 ).time() ), periods.get( 7 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2012, 1, 1 ).time() ), periods.get( 8 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2013, 1, 1 ).time() ), periods.get( 9 ) );
+        assertEquals( periodType.createPeriod( new Cal( 2014, 1, 1 ).time() ), periods.get( 10 ) );
     }
 }