← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19854: rewrote plus/minus days calculation in Ethiopean calendar, and uses this for month/year calculati...

 

------------------------------------------------------------
revno: 19854
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-08-26 14:25:42 +0700
message:
  rewrote plus/minus days calculation in Ethiopean calendar, and uses this for month/year calculation also
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopianCalendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.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/FinancialJulyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.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/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/SixMonthlyAprilPeriodType.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/TwoYearlyPeriodType.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/calendar/impl/EthiopianCalendarTest.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/impl/EthiopianCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopianCalendar.java	2015-08-26 06:03:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopianCalendar.java	2015-08-26 07:25:42 +0000
@@ -94,30 +94,112 @@
     @Override
     public DateTimeUnit plusDays( DateTimeUnit dateTimeUnit, int days )
     {
-        dateTimeUnit = super.plusDays( dateTimeUnit, days );
-
-        if ( dateTimeUnit.getMonth() > 12 )
-        {
-            dateTimeUnit.setYear( dateTimeUnit.getYear() + 1 );
-            dateTimeUnit.setMonth( 1 );
-            dateTimeUnit.setDay( 1 );
-        }
-
-        return dateTimeUnit;
+        int curYear = dateTimeUnit.getYear();
+        int curMonth = dateTimeUnit.getMonth();
+        int curDay = dateTimeUnit.getDay();
+        int dayOfWeek = dateTimeUnit.getDayOfWeek();
+
+        while ( days != 0 )
+        {
+            curDay++;
+
+            if ( curDay > 30 )
+            {
+                curMonth++;
+                curDay = 1;
+            }
+
+            if ( curMonth > 12 )
+            {
+                curYear++;
+                curMonth = 1;
+            }
+
+            dayOfWeek++;
+
+            if ( dayOfWeek > 7 )
+            {
+                dayOfWeek = 1;
+            }
+
+            days--;
+        }
+
+        return new DateTimeUnit( curYear, curMonth, curDay, dayOfWeek );
+    }
+
+    @Override
+    public DateTimeUnit minusDays( DateTimeUnit dateTimeUnit, int days )
+    {
+        int curYear = dateTimeUnit.getYear();
+        int curMonth = dateTimeUnit.getMonth();
+        int curDay = dateTimeUnit.getDay();
+        int dayOfWeek = dateTimeUnit.getDayOfWeek();
+
+        while ( days != 0 )
+        {
+            curDay--;
+
+            if ( curDay == 0 )
+            {
+                curMonth--;
+
+                if ( curMonth == 0 )
+                {
+                    curYear--;
+                    curMonth = 12;
+                }
+
+                curDay = 30;
+            }
+
+            dayOfWeek--;
+
+            if ( dayOfWeek == 0 )
+            {
+                dayOfWeek = 7;
+            }
+
+            days--;
+        }
+
+        return new DateTimeUnit( curYear, curMonth, curDay, dayOfWeek );
+    }
+
+    @Override
+    public DateTimeUnit plusWeeks( DateTimeUnit dateTimeUnit, int weeks )
+    {
+        return plusDays( dateTimeUnit, weeks * 7 );
+    }
+
+    @Override
+    public DateTimeUnit minusWeeks( DateTimeUnit dateTimeUnit, int weeks )
+    {
+        return minusDays( dateTimeUnit, weeks * 7 );
     }
 
     @Override
     public DateTimeUnit plusMonths( DateTimeUnit dateTimeUnit, int months )
     {
-        dateTimeUnit = super.plusMonths( dateTimeUnit, months );
-
-        if ( dateTimeUnit.getMonth() > 12 )
-        {
-            dateTimeUnit.setYear( dateTimeUnit.getYear() + 1 );
-            dateTimeUnit.setMonth( 1 );
-        }
-
-        return dateTimeUnit;
+        return plusDays( dateTimeUnit, months * 30 );
+    }
+
+    @Override
+    public DateTimeUnit minusMonths( DateTimeUnit dateTimeUnit, int months )
+    {
+        return minusDays( dateTimeUnit, months * 30 );
+    }
+
+    @Override
+    public DateTimeUnit plusYears( DateTimeUnit dateTimeUnit, int years )
+    {
+        return plusDays( dateTimeUnit, years * (12 * 30) );
+    }
+
+    @Override
+    public DateTimeUnit minusYears( DateTimeUnit dateTimeUnit, int years )
+    {
+        return minusDays( dateTimeUnit, years * (12 * 30) );
     }
 
     @Override
@@ -136,4 +218,10 @@
 
         return 30;
     }
+
+    @Override
+    public int daysInWeek()
+    {
+        return 7;
+    }
 }

=== 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	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -42,7 +42,7 @@
     extends CalendarPeriodType
 {
     private static final String ISO_FORMAT = "yyyyMMB";
-    
+
     private static final String ISO8601_DURATION = "P2M";
 
     /**
@@ -140,7 +140,7 @@
         Calendar cal = getCalendar();
 
         dateTimeUnit.setDay( 1 );
-        dateTimeUnit = cal.minusMonths( dateTimeUnit, ( dateTimeUnit.getMonth() % 2 ) + 10 );
+        dateTimeUnit = cal.minusMonths( dateTimeUnit, (dateTimeUnit.getMonth() % 2) + 10 );
 
         List<Period> periods = Lists.newArrayList();
 
@@ -154,9 +154,9 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
     {
-        return String.format( "%d%02dB", dateTimeUnit.getYear(), ( dateTimeUnit.getMonth() + 1 ) / 2 );
+        return String.format( "%d%02dB", dateTimeUnit.getYear(), (dateTimeUnit.getMonth() + 1) / 2 );
     }
 
     @Override
@@ -180,8 +180,8 @@
     }
 
     @Override
-    public String getIso8601Duration() 
+    public String getIso8601Duration()
     {
-        return ISO8601_DURATION; 
+        return ISO8601_DURATION;
     }
 }

=== 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	2015-08-26 06:03:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -156,7 +156,7 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
     {
         return String.format( "%d%02d%02d", dateTimeUnit.getYear(), dateTimeUnit.getMonth(), dateTimeUnit.getDay() );
     }

=== 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	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java	2015-08-26 07:25:42 +0000
@@ -44,7 +44,7 @@
     private static final long serialVersionUID = 8790198046182231889L;
 
     private static final String ISO_FORMAT = "yyyyApril";
-    
+
     private static final String ISO8601_DURATION = "P1Y";
 
     public static final String NAME = "FinancialApril";
@@ -54,7 +54,7 @@
     {
         return Calendar.APRIL;
     }
-    
+
     @Override
     public String getName()
     {
@@ -62,7 +62,7 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar )
     {
         return String.format( "%dApril", dateTimeUnit.getYear() );
     }
@@ -72,11 +72,11 @@
     {
         return ISO_FORMAT;
     }
-    
+
     @Override
-    public String getIso8601Duration() 
+    public String getIso8601Duration()
     {
-        return ISO8601_DURATION; 
+        return ISO8601_DURATION;
     }
 
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialJulyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -44,7 +44,7 @@
     private static final long serialVersionUID = 5190072405972068226L;
 
     private static final String ISO_FORMAT = "yyyyJuly";
-    
+
     private static final String ISO8601_DURATION = "P1Y";
 
     public static final String NAME = "FinancialJuly";
@@ -54,7 +54,7 @@
     {
         return Calendar.JULY;
     }
-    
+
     @Override
     public String getName()
     {
@@ -62,7 +62,7 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar )
     {
         return String.format( "%dJuly", dateTimeUnit.getYear() );
     }
@@ -72,11 +72,11 @@
     {
         return ISO_FORMAT;
     }
-    
+
     @Override
-    public String getIso8601Duration() 
+    public String getIso8601Duration()
     {
-        return ISO8601_DURATION; 
+        return ISO8601_DURATION;
     }
 
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialOctoberPeriodType.java	2015-08-26 07:25:42 +0000
@@ -44,7 +44,7 @@
     private static final long serialVersionUID = -1623576547899897811L;
 
     private static final String ISO_FORMAT = "yyyyOct";
-    
+
     private static final String ISO8601_DURATION = "P1Y";
 
     public static final String NAME = "FinancialOct";
@@ -62,7 +62,7 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar )
     {
         return String.format( "%dOct", dateTimeUnit.getYear() );
     }
@@ -72,11 +72,11 @@
     {
         return ISO_FORMAT;
     }
-    
+
     @Override
-    public String getIso8601Duration() 
+    public String getIso8601Duration()
     {
-        return ISO8601_DURATION; 
+        return ISO8601_DURATION;
     }
 
 }

=== 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	2015-08-26 06:03:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -161,7 +161,7 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
     {
         return String.format( "%d%02d", dateTimeUnit.getYear(), dateTimeUnit.getMonth() );
     }

=== 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	2015-08-24 07:46:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2015-08-26 07:25:42 +0000
@@ -300,9 +300,7 @@
 
     public Period toIsoPeriod( DateTimeUnit start, DateTimeUnit end )
     {
-        org.hisp.dhis.calendar.Calendar cal = getCalendar();
-
-        return toIsoPeriod( start, end, cal );
+        return toIsoPeriod( start, end, getCalendar() );
     }
 
     protected Period toIsoPeriod( DateTimeUnit start, DateTimeUnit end, org.hisp.dhis.calendar.Calendar calendar )
@@ -310,7 +308,7 @@
         DateTimeUnit from = calendar.toIso( start );
         DateTimeUnit to = calendar.toIso( end );
 
-        return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( start ) );
+        return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( start, calendar ) );
     }
 
     public Period toIsoPeriod( DateTimeUnit dateTimeUnit )
@@ -525,7 +523,18 @@
      * @param dateTimeUnit Period
      * @return the period as string
      */
-    public abstract String getIsoDate( DateTimeUnit dateTimeUnit );
+    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    {
+        return getIsoDate( dateTimeUnit, getCalendar() );
+    }
+
+    /**
+     * Returns an iso8601 formatted string representation of the dataUnit
+     *
+     * @param dateTimeUnit Period
+     * @return the period as string
+     */
+    public abstract String getIsoDate( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar );
 
     /**
      * Generates a period based on the given iso8601 formatted string.

=== 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	2015-08-24 08:48:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -178,7 +178,7 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar  )
     {
         switch ( dateTimeUnit.getMonth() )
         {

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAprilPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAprilPeriodType.java	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAprilPeriodType.java	2015-08-26 07:25:42 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.calendar.Calendar;
 import org.hisp.dhis.calendar.DateTimeUnit;
 import org.joda.time.DateTimeConstants;
 
@@ -78,13 +79,13 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
     {
         int month = dateTimeUnit.getMonth();
 
         if ( dateTimeUnit.isIso8601() )
         {
-            month = getCalendar().fromIso( dateTimeUnit ).getMonth();
+            month = calendar.fromIso( dateTimeUnit ).getMonth();
         }
 
         switch ( month )
@@ -106,11 +107,11 @@
     {
         return ISO_FORMAT;
     }
-    
+
     @Override
-    public String getIso8601Duration() 
+    public String getIso8601Duration()
     {
-        return ISO8601_DURATION; 
+        return ISO8601_DURATION;
     }
 
 }

=== 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	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.calendar.Calendar;
 import org.hisp.dhis.calendar.DateTimeUnit;
 import org.joda.time.DateTimeConstants;
 
@@ -79,13 +80,13 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
     {
         int month = dateTimeUnit.getMonth();
 
         if ( dateTimeUnit.isIso8601() )
         {
-            month = getCalendar().fromIso( dateTimeUnit ).getMonth();
+            month = calendar.fromIso( dateTimeUnit ).getMonth();
         }
 
         switch ( month )
@@ -107,11 +108,11 @@
     {
         return ISO_FORMAT;
     }
-    
+
     @Override
-    public String getIso8601Duration() 
+    public String getIso8601Duration()
     {
-        return ISO8601_DURATION; 
+        return ISO8601_DURATION;
     }
 
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -200,7 +200,7 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar )
     {
         return null; // TODO
     }

=== 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	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -29,7 +29,6 @@
  */
 
 import com.google.common.collect.Lists;
-
 import org.hisp.dhis.calendar.Calendar;
 import org.hisp.dhis.calendar.DateInterval;
 import org.hisp.dhis.calendar.DateIntervalType;
@@ -122,19 +121,19 @@
     @Override
     public List<Period> generatePeriods( DateTimeUnit dateTimeUnit )
     {
-        Calendar cal = getCalendar();
-        
+        Calendar calendar = getCalendar();
+
         List<Period> periods = Lists.newArrayList();
 
         // rewind to start of week
-        dateTimeUnit = cal.minusDays( dateTimeUnit, cal.weekday( dateTimeUnit ) - 1 );
+        dateTimeUnit = calendar.minusDays( dateTimeUnit, calendar.weekday( dateTimeUnit ) - 1 );
 
-        for ( int i = 0; i < cal.weeksInYear( dateTimeUnit.getYear() ); i++ )
+        for ( int i = 0; i < calendar.weeksInYear( dateTimeUnit.getYear() ); i++ )
         {
-            DateInterval interval = cal.toInterval( dateTimeUnit, DateIntervalType.ISO8601_WEEK );
+            DateInterval interval = calendar.toInterval( dateTimeUnit, DateIntervalType.ISO8601_WEEK );
             periods.add( new Period( this, interval.getFrom().toJdkDate(), interval.getTo().toJdkDate() ) );
 
-            dateTimeUnit = cal.plusWeeks( dateTimeUnit, 1 );
+            dateTimeUnit = calendar.plusWeeks( dateTimeUnit, 1 );
         }
 
         return periods;
@@ -147,16 +146,16 @@
     @Override
     public List<Period> generateRollingPeriods( DateTimeUnit dateTimeUnit )
     {
-        Calendar cal = getCalendar();
-        
+        Calendar calendar = getCalendar();
+
         List<Period> periods = Lists.newArrayList();
-        dateTimeUnit = cal.minusDays( dateTimeUnit, cal.weekday( dateTimeUnit ) - 1 );
-        dateTimeUnit = cal.minusDays( dateTimeUnit, 357 );
+        dateTimeUnit = calendar.minusDays( dateTimeUnit, calendar.weekday( dateTimeUnit ) - 1 );
+        dateTimeUnit = calendar.minusDays( dateTimeUnit, 357 );
 
         for ( int i = 0; i < 52; i++ )
         {
-            periods.add( createPeriod( dateTimeUnit, cal ) );
-            dateTimeUnit = cal.plusWeeks( dateTimeUnit, 1 );
+            periods.add( createPeriod( dateTimeUnit, calendar ) );
+            dateTimeUnit = calendar.plusWeeks( dateTimeUnit, 1 );
         }
 
         return periods;
@@ -167,13 +166,11 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
     {
-        Calendar cal = getCalendar();
-        
-        int week = cal.week( dateTimeUnit );
+        int week = calendar.week( dateTimeUnit );
 
-        if ( week == 1 && dateTimeUnit.getMonth() == cal.monthsInYear() )
+        if ( week == 1 && dateTimeUnit.getMonth() == calendar.monthsInYear() )
         {
             dateTimeUnit.setYear( dateTimeUnit.getYear() + 1 );
         }
@@ -189,11 +186,11 @@
     {
         return ISO_FORMAT;
     }
-    
+
     @Override
-    public String getIso8601Duration() 
+    public String getIso8601Duration()
     {
-        return ISO8601_DURATION; 
+        return ISO8601_DURATION;
     }
 
 
@@ -201,7 +198,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/main/java/org/hisp/dhis/period/YearlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2015-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2015-08-26 07:25:42 +0000
@@ -29,7 +29,6 @@
  */
 
 import com.google.common.collect.Lists;
-
 import org.hisp.dhis.calendar.Calendar;
 import org.hisp.dhis.calendar.DateTimeUnit;
 
@@ -52,7 +51,7 @@
     private static final long serialVersionUID = 3893035414025085437L;
 
     private static final String ISO_FORMAT = "yyyy";
-    
+
     private static final String ISO8601_DURATION = "P1Y";
 
     /**
@@ -122,7 +121,7 @@
     public List<Period> generatePeriods( DateTimeUnit dateTimeUnit )
     {
         Calendar cal = getCalendar();
-        
+
         dateTimeUnit = cal.minusYears( dateTimeUnit, 5 );
         dateTimeUnit.setDay( 1 );
         dateTimeUnit.setMonth( 1 );
@@ -162,7 +161,7 @@
     public List<Period> generateLast5Years( Date date )
     {
         Calendar cal = getCalendar();
-        
+
         DateTimeUnit dateTimeUnit = createLocalDateUnitInstance( date );
         dateTimeUnit = cal.minusYears( dateTimeUnit, 4 );
         dateTimeUnit.setDay( 1 );
@@ -180,7 +179,7 @@
     }
 
     @Override
-    public String getIsoDate( DateTimeUnit dateTimeUnit )
+    public String getIsoDate( DateTimeUnit dateTimeUnit, Calendar calendar )
     {
         return String.valueOf( dateTimeUnit.getYear() );
     }
@@ -190,11 +189,11 @@
     {
         return ISO_FORMAT;
     }
-    
+
     @Override
-    public String getIso8601Duration() 
+    public String getIso8601Duration()
     {
-        return ISO8601_DURATION; 
+        return ISO8601_DURATION;
     }
 
 
@@ -202,7 +201,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/impl/EthiopianCalendarTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/impl/EthiopianCalendarTest.java	2015-08-26 06:03:30 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/impl/EthiopianCalendarTest.java	2015-08-26 07:25:42 +0000
@@ -35,6 +35,7 @@
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.QuarterlyPeriodType;
+import org.hisp.dhis.period.WeeklyPeriodType;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -108,4 +109,53 @@
         List<Period> monthly = new MonthlyPeriodType().generatePeriods( calendar, startDate, endDate );
         assertEquals( 601, monthly.size() );
     }
+
+    @Test
+    public void testGenerateWeeklyPeriods()
+    {
+        Date startDate = new Cal( 1975, 1, 1, true ).time();
+        Date endDate = new Cal( 2025, 1, 2, true ).time();
+
+        List<Period> weeks = new WeeklyPeriodType().generatePeriods( calendar, startDate, endDate );
+        assertEquals( 2610, weeks.size() );
+    }
+
+    @Test
+    public void testPlusDays()
+    {
+        DateTimeUnit dateTimeUnit = new DateTimeUnit( 2006, 1, 1 );
+
+        DateTimeUnit testDateTimeUnit = calendar.plusDays( dateTimeUnit, 43 );
+        assertEquals( 2006, testDateTimeUnit.getYear() );
+        assertEquals( 2, testDateTimeUnit.getMonth() );
+        assertEquals( 14, testDateTimeUnit.getDay() );
+
+        testDateTimeUnit = calendar.plusDays( dateTimeUnit, 65 );
+        assertEquals( 2006, testDateTimeUnit.getYear() );
+        assertEquals( 3, testDateTimeUnit.getMonth() );
+        assertEquals( 6, testDateTimeUnit.getDay() );
+
+        testDateTimeUnit = calendar.plusDays( dateTimeUnit, (12 * 30) + 5 );
+        assertEquals( 2007, testDateTimeUnit.getYear() );
+        assertEquals( 1, testDateTimeUnit.getMonth() );
+        assertEquals( 6, testDateTimeUnit.getDay() );
+
+        dateTimeUnit = new DateTimeUnit( 2006, 2, 29 );
+
+        testDateTimeUnit = calendar.plusDays( dateTimeUnit, 10 );
+        assertEquals( 2006, testDateTimeUnit.getYear() );
+        assertEquals( 3, testDateTimeUnit.getMonth() );
+        assertEquals( 9, testDateTimeUnit.getDay() );
+    }
+
+    @Test
+    public void testMinusDays()
+    {
+        DateTimeUnit dateTimeUnit = new DateTimeUnit( 2007, 1, 1 );
+
+        DateTimeUnit testDateTimeUnit = calendar.minusDays( dateTimeUnit, 2 );
+        assertEquals( 2006, testDateTimeUnit.getYear() );
+        assertEquals( 12, testDateTimeUnit.getMonth() );
+        assertEquals( 29, testDateTimeUnit.getDay() );
+    }
 }