← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16464: optimize getNext/Previous periods in PeriodType, reuse calendar instance to creating local dateUn...

 

------------------------------------------------------------
revno: 16464
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-08-21 14:44:41 +0700
message:
  optimize getNext/Previous periods in PeriodType, reuse calendar instance to creating local dateUnit instance
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.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/SixMonthlyAbstractPeriodType.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


--
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/DailyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java	2014-08-21 07:39:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java	2014-08-21 07:44:41 +0000
@@ -87,7 +87,7 @@
     @Override
     public Period getNextPeriod( Period period, Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.plusDays( dateUnit, 1 );
 
         Date date = calendar.toIso( dateUnit ).toJdkDate();
@@ -98,7 +98,7 @@
     @Override
     public Period getPreviousPeriod( Period period, Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.minusDays( dateUnit, 1 );
 
         Date date = calendar.toIso( dateUnit ).toJdkDate();
@@ -173,7 +173,7 @@
         date = date != null ? date : new Date();
         rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
 
-        DateUnit dateUnit = createLocalDateUnitInstance( date );
+        DateUnit dateUnit = createLocalDateUnitInstance( date, cal );
         dateUnit = cal.minusDays( dateUnit, rewindedPeriods );
 
         return cal.toIso( dateUnit ).toJdkDate();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java	2014-08-21 07:39:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java	2014-08-21 07:44:41 +0000
@@ -93,7 +93,7 @@
     @Override
     public Period getNextPeriod( Period period, Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.plusYears( dateUnit, 1 );
 
         return createPeriod( dateUnit, calendar );
@@ -102,7 +102,7 @@
     @Override
     public Period getPreviousPeriod( Period period, Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.minusYears( dateUnit, 1 );
 
         return createPeriod( dateUnit, calendar );
@@ -157,7 +157,7 @@
     {
         Calendar cal = getCalendar();
 
-        DateUnit dateUnit = createLocalDateUnitInstance( date );
+        DateUnit dateUnit = createLocalDateUnitInstance( date, cal );
         boolean past = dateUnit.getMonth() >= (getBaseMonth() + 1);
 
         List<Period> periods = Lists.newArrayList();
@@ -183,7 +183,7 @@
         date = date != null ? date : new Date();
         rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
 
-        DateUnit dateUnit = createLocalDateUnitInstance( date );
+        DateUnit dateUnit = createLocalDateUnitInstance( date, cal );
         dateUnit = cal.minusYears( dateUnit, rewindedPeriods );
 
         return cal.toIso( dateUnit ).toJdkDate();

=== 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	2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2014-08-21 07:44:41 +0000
@@ -327,6 +327,17 @@
     }
 
     /**
+     * Returns an instance of a DateUnit.
+     *
+     * @param date date of calendar in local calendar
+     * @return an instance of a Calendar without any time of day.
+     */
+    public static DateUnit createLocalDateUnitInstance( Date date, org.hisp.dhis.calendar.Calendar calendar )
+    {
+        return calendar.fromIso( DateUnit.fromJdkDate( date ) );
+    }
+
+    /**
      * Clears the time of day in a Calendar instance.
      *
      * @param calendar the Calendar to fix.

=== 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	2014-08-20 10:58:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java	2014-08-21 07:44:41 +0000
@@ -98,7 +98,7 @@
     @Override
     public Period getNextPeriod( Period period, org.hisp.dhis.calendar.Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.plusMonths( dateUnit, 3 );
 
         return createPeriod( dateUnit, calendar );
@@ -107,7 +107,7 @@
     @Override
     public Period getPreviousPeriod( Period period, org.hisp.dhis.calendar.Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.minusMonths( dateUnit, 3 );
 
         return createPeriod( dateUnit, calendar );

=== 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-20 10:58:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAbstractPeriodType.java	2014-08-21 07:44:41 +0000
@@ -123,7 +123,7 @@
         Calendar cal = getCalendar();
         
         Period period = createPeriod( dateUnit, cal );
-        dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        dateUnit = createLocalDateUnitInstance( period.getStartDate(), cal );
 
         List<Period> periods = Lists.newArrayList();
 

=== 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-08-20 10:58:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2014-08-21 07:44:41 +0000
@@ -98,7 +98,7 @@
     @Override
     public Period getNextPeriod( Period period, Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.plusWeeks( dateUnit, 1 );
 
         return createPeriod( dateUnit, calendar );
@@ -107,7 +107,7 @@
     @Override
     public Period getPreviousPeriod( Period period, Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.minusWeeks( dateUnit, 1 );
 
         return createPeriod( dateUnit, calendar );

=== 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	2014-08-20 10:58:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java	2014-08-21 07:44:41 +0000
@@ -98,7 +98,7 @@
     @Override
     public Period getNextPeriod( Period period, Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.plusYears( dateUnit, 1 );
 
         return createPeriod( dateUnit, calendar );
@@ -107,7 +107,7 @@
     @Override
     public Period getPreviousPeriod( Period period, Calendar calendar )
     {
-        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
+        DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate(), calendar );
         dateUnit = calendar.minusYears( dateUnit, 1 );
 
         return createPeriod( dateUnit, calendar );