dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31098
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15814: Period types, reusing calendars with variables instead of retrieving new instances, improves perf...
------------------------------------------------------------
revno: 15814
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-06-23 16:31:05 +0200
message:
Period types, reusing calendars with variables instead of retrieving new instances, improves performance when generating date period resource table
modified:
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/FinancialPeriodType.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/SixMonthlyAbstractPeriodType.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
--
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/BiMonthlyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java 2014-05-21 15:31:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java 2014-06-23 14:31:05 +0000
@@ -29,6 +29,8 @@
*/
import com.google.common.collect.Lists;
+
+import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateUnit;
import java.util.Date;
@@ -60,7 +62,7 @@
}
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, Calendar calendar )
{
DateUnit start = new DateUnit( dateUnit );
start.setMonth( ((start.getMonth() - 1) - (start.getMonth() - 1) % 2) + 1 );
@@ -68,8 +70,8 @@
DateUnit end = new DateUnit( start );
- end = getCalendar().plusMonths( end, 1 );
- end.setDay( getCalendar().daysInMonth( end.getYear(), end.getMonth() ) );
+ end = calendar.plusMonths( end, 1 );
+ end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
return toIsoPeriod( start, end );
}
@@ -87,19 +89,23 @@
@Override
public Period getNextPeriod( Period period )
{
- DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 2 );
+ Calendar cal = getCalendar();
+
+ DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
+ dateUnit = cal.plusMonths( dateUnit, 2 );
- return createPeriod( getCalendar().toIso( dateUnit ) );
+ return createPeriod( cal.toIso( dateUnit ), cal );
}
@Override
public Period getPreviousPeriod( Period period )
{
- DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
- dateUnit = getCalendar().minusMonths( dateUnit, 2 );
+ Calendar cal = getCalendar();
+
+ DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
+ dateUnit = cal.minusMonths( dateUnit, 2 );
- return createPeriod( getCalendar().toIso( dateUnit ) );
+ return createPeriod( cal.toIso( dateUnit ), cal );
}
/**
@@ -109,6 +115,8 @@
@Override
public List<Period> generatePeriods( DateUnit dateUnit )
{
+ Calendar cal = getCalendar();
+
dateUnit.setMonth( 1 );
dateUnit.setDay( 1 );
@@ -118,8 +126,8 @@
while ( dateUnit.getYear() == year )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 2 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusMonths( dateUnit, 2 );
}
return periods;
@@ -132,15 +140,17 @@
@Override
public List<Period> generateRollingPeriods( DateUnit dateUnit )
{
+ Calendar cal = getCalendar();
+
dateUnit.setDay( 1 );
- dateUnit = getCalendar().minusMonths( dateUnit, (dateUnit.getMonth() % 2) + 10 );
+ dateUnit = cal.minusMonths( dateUnit, (dateUnit.getMonth() % 2) + 10 );
List<Period> periods = Lists.newArrayList();
for ( int i = 0; i < 6; i++ )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 2 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusMonths( dateUnit, 2 );
}
return periods;
@@ -161,12 +171,14 @@
@Override
public Date getRewindedDate( Date date, Integer rewindedPeriods )
{
+ Calendar cal = getCalendar();
+
date = date != null ? date : new Date();
rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
- DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( date ) );
- dateUnit = getCalendar().minusMonths( dateUnit, rewindedPeriods );
+ DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( date ) );
+ dateUnit = cal.minusMonths( dateUnit, rewindedPeriods );
- return getCalendar().toIso( dateUnit ).toJdkDate();
+ return cal.toIso( dateUnit ).toJdkDate();
}
}
=== 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-05-21 11:52:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/DailyPeriodType.java 2014-06-23 14:31:05 +0000
@@ -29,6 +29,8 @@
*/
import com.google.common.collect.Lists;
+
+import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateUnit;
import java.util.Date;
@@ -68,7 +70,7 @@
}
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, Calendar calendar )
{
return toIsoPeriod( dateUnit );
}
@@ -86,10 +88,12 @@
@Override
public Period getNextPeriod( Period period )
{
+ Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
- dateUnit = getCalendar().plusDays( dateUnit, 1 );
+ dateUnit = cal.plusDays( dateUnit, 1 );
- Date date = getCalendar().toIso( dateUnit ).toJdkDate();
+ Date date = cal.toIso( dateUnit ).toJdkDate();
return new Period( this, date, date );
}
@@ -97,10 +101,12 @@
@Override
public Period getPreviousPeriod( Period period )
{
+ Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
- dateUnit = getCalendar().minusDays( dateUnit, 1 );
+ dateUnit = cal.minusDays( dateUnit, 1 );
- Date date = getCalendar().toIso( dateUnit ).toJdkDate();
+ Date date = cal.toIso( dateUnit ).toJdkDate();
return new Period( this, date, date );
}
@@ -121,7 +127,7 @@
while ( year == dateUnit.getYear() )
{
- periods.add( createPeriod( dateUnit ) );
+ periods.add( createPeriod( dateUnit, null ) );
dateUnit = getCalendar().plusDays( dateUnit, 1 );
}
@@ -135,14 +141,16 @@
@Override
public List<Period> generateRollingPeriods( DateUnit dateUnit )
{
- dateUnit = getCalendar().minusDays( dateUnit, 364 );
+ Calendar cal = getCalendar();
+
+ dateUnit = cal.minusDays( dateUnit, 364 );
List<Period> periods = Lists.newArrayList();
for ( int i = 0; i < 365; i++ )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusDays( dateUnit, 1 );
+ periods.add( createPeriod( dateUnit, null ) );
+ dateUnit = cal.plusDays( dateUnit, 1 );
}
return periods;
@@ -163,12 +171,14 @@
@Override
public Date getRewindedDate( Date date, Integer rewindedPeriods )
{
+ Calendar cal = getCalendar();
+
date = date != null ? date : new Date();
rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
DateUnit dateUnit = createLocalDateUnitInstance( date );
- dateUnit = getCalendar().minusDays( dateUnit, rewindedPeriods );
+ dateUnit = cal.minusDays( dateUnit, rewindedPeriods );
- return getCalendar().toIso( dateUnit ).toJdkDate();
+ 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-05-21 11:52:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java 2014-06-23 14:31:05 +0000
@@ -29,6 +29,8 @@
*/
import com.google.common.collect.Lists;
+
+import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateUnit;
import java.util.Date;
@@ -58,7 +60,7 @@
// -------------------------------------------------------------------------
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, Calendar calendar )
{
boolean past = dateUnit.getMonth() >= (getBaseMonth() + 1);
@@ -95,7 +97,7 @@
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
dateUnit = getCalendar().plusYears( dateUnit, 1 );
- return createPeriod( dateUnit );
+ return createPeriod( dateUnit, null );
}
@Override
@@ -104,7 +106,7 @@
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
dateUnit = getCalendar().minusYears( dateUnit, 1 );
- return createPeriod( dateUnit );
+ return createPeriod( dateUnit, null );
}
/**
@@ -124,7 +126,7 @@
for ( int i = 0; i < 11; i++ )
{
- periods.add( createPeriod( dateUnit ) );
+ periods.add( createPeriod( dateUnit, null ) );
dateUnit = getCalendar().plusYears( dateUnit, 1 );
}
@@ -161,7 +163,7 @@
for ( int i = 0; i < 5; i++ )
{
- periods.add( createPeriod( dateUnit ) );
+ periods.add( createPeriod( dateUnit, null ) );
dateUnit = getCalendar().plusYears( dateUnit, 1 );
}
=== 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 2014-05-23 15:01:06 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java 2014-06-23 14:31:05 +0000
@@ -29,6 +29,8 @@
*/
import com.google.common.collect.Lists;
+
+import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateUnit;
import java.util.Date;
@@ -70,13 +72,13 @@
}
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, Calendar calendar )
{
DateUnit start = new DateUnit( dateUnit );
start.setDay( 1 );
DateUnit end = new DateUnit( dateUnit );
- end.setDay( getCalendar().daysInMonth( end.getYear(), end.getMonth() ) );
+ end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
return toIsoPeriod( start, end );
}
@@ -94,19 +96,23 @@
@Override
public Period getNextPeriod( Period period )
{
- DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 1 );
+ Calendar cal = getCalendar();
+
+ DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
+ dateUnit = cal.plusMonths( dateUnit, 1 );
- return createPeriod( getCalendar().toIso( dateUnit ) );
+ return createPeriod( cal.toIso( dateUnit ), cal );
}
@Override
public Period getPreviousPeriod( Period period )
{
- DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
- dateUnit = getCalendar().minusMonths( dateUnit, 1 );
+ Calendar cal = getCalendar();
+
+ DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
+ dateUnit = cal.minusMonths( dateUnit, 1 );
- return createPeriod( getCalendar().toIso( dateUnit ) );
+ return createPeriod( cal.toIso( dateUnit ), cal );
}
/**
@@ -116,6 +122,8 @@
@Override
public List<Period> generatePeriods( DateUnit dateUnit )
{
+ Calendar cal = getCalendar();
+
dateUnit.setMonth( 1 );
dateUnit.setDay( 1 );
@@ -125,8 +133,8 @@
while ( dateUnit.getYear() == year )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 1 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusMonths( dateUnit, 1 );
}
return periods;
@@ -139,15 +147,17 @@
@Override
public List<Period> generateRollingPeriods( DateUnit dateUnit )
{
+ Calendar cal = getCalendar();
+
dateUnit.setDay( 1 );
- dateUnit = getCalendar().minusMonths( dateUnit, 11 );
+ dateUnit = cal.minusMonths( dateUnit, 11 );
List<Period> periods = Lists.newArrayList();
for ( int i = 0; i < 12; i++ )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 1 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusMonths( dateUnit, 1 );
}
return periods;
@@ -168,12 +178,14 @@
@Override
public Date getRewindedDate( Date date, Integer rewindedPeriods )
{
+ Calendar cal = getCalendar();
+
date = date != null ? date : new Date();
rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
- DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( date ) );
- dateUnit = getCalendar().minusMonths( dateUnit, rewindedPeriods );
+ DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( date ) );
+ dateUnit = cal.minusMonths( dateUnit, rewindedPeriods );
- return getCalendar().toIso( dateUnit ).toJdkDate();
+ 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-05-21 11:52:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2014-06-23 14:31:05 +0000
@@ -225,7 +225,9 @@
public Period createPeriod( Calendar cal )
{
- return createPeriod( getCalendar().fromIso( DateUnit.fromJdkCalendar( cal ) ) );
+ org.hisp.dhis.calendar.Calendar calendar = getCalendar();
+
+ return createPeriod( calendar.fromIso( DateUnit.fromJdkCalendar( cal ) ), calendar );
}
public Period toIsoPeriod( DateUnit start, DateUnit end )
@@ -237,8 +239,8 @@
{
return toIsoPeriod( dateUnit, dateUnit );
}
-
- public abstract Period createPeriod( DateUnit dateUnit );
+
+ public abstract Period createPeriod( DateUnit dateUnit, org.hisp.dhis.calendar.Calendar calendar );
/**
* Returns a comparable value for the frequency length of this PeriodType.
=== 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-05-21 15:04:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java 2014-06-23 14:31:05 +0000
@@ -71,16 +71,16 @@
}
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, org.hisp.dhis.calendar.Calendar calendar )
{
DateUnit start = new DateUnit( dateUnit );
- start.setMonth( ((dateUnit.getMonth() - 1) - ((dateUnit.getMonth() - 1) % 3)) + 1 );
+ start.setMonth( ( ( dateUnit.getMonth() - 1 ) - ( ( dateUnit.getMonth() - 1 ) % 3 ) ) + 1 );
start.setDay( 1 );
DateUnit end = new DateUnit( start );
- end = getCalendar().plusMonths( end, 2 );
- end.setDay( getCalendar().daysInMonth( end.getYear(), end.getMonth() ) );
+ end = calendar.plusMonths( end, 2 );
+ end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
return toIsoPeriod( start, end );
}
@@ -98,19 +98,23 @@
@Override
public Period getNextPeriod( Period period )
{
+ org.hisp.dhis.calendar.Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
- dateUnit = getCalendar().plusMonths( dateUnit, 3 );
+ dateUnit = cal.plusMonths( dateUnit, 3 );
- return createPeriod( dateUnit );
+ return createPeriod( dateUnit, cal );
}
@Override
public Period getPreviousPeriod( Period period )
{
+ org.hisp.dhis.calendar.Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
- dateUnit = getCalendar().minusMonths( dateUnit, 3 );
+ dateUnit = cal.minusMonths( dateUnit, 3 );
- return createPeriod( dateUnit );
+ return createPeriod( dateUnit, cal );
}
/**
@@ -120,6 +124,8 @@
@Override
public List<Period> generatePeriods( DateUnit dateUnit )
{
+ org.hisp.dhis.calendar.Calendar cal = getCalendar();
+
dateUnit.setMonth( 1 );
dateUnit.setDay( 1 );
@@ -128,8 +134,8 @@
while ( year == dateUnit.getYear() )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 3 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusMonths( dateUnit, 3 );
}
return periods;
@@ -150,16 +156,18 @@
@Override
public List<Period> generateRollingPeriods( DateUnit dateUnit )
{
+ org.hisp.dhis.calendar.Calendar cal = getCalendar();
+
dateUnit.setDay( 1 );
- dateUnit = getCalendar().minusMonths( dateUnit, 9 );
+ dateUnit = cal.minusMonths( dateUnit, 9 );
List<Period> periods = Lists.newArrayList();
for ( int i = 0; i < 4; i++ )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 3 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusMonths( dateUnit, 3 );
}
return periods;
@@ -229,12 +237,14 @@
@Override
public Date getRewindedDate( Date date, Integer rewindedPeriods )
{
+ org.hisp.dhis.calendar.Calendar cal = getCalendar();
+
date = date != null ? date : new Date();
rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
DateUnit dateUnit = createLocalDateUnitInstance( date );
- dateUnit = getCalendar().minusMonths( dateUnit, rewindedPeriods * 3 );
+ dateUnit = cal.minusMonths( dateUnit, rewindedPeriods * 3 );
- return getCalendar().toIso( dateUnit ).toJdkDate();
+ return cal.toIso( dateUnit ).toJdkDate();
}
}
=== 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-05-21 12:12:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAbstractPeriodType.java 2014-06-23 14:31:05 +0000
@@ -29,6 +29,8 @@
*/
import com.google.common.collect.Lists;
+
+import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateUnit;
import java.util.Date;
@@ -60,24 +62,25 @@
// -------------------------------------------------------------------------
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, Calendar calendar )
{
- int year = getCalendar().monthsInYear() * dateUnit.getYear();
+ int year = calendar.monthsInYear() * dateUnit.getYear();
int yearMonth = year + dateUnit.getMonth() - getBaseMonth();
// TODO how should we handle years with odd number of months? (Ethiopian)
+
int months = (((yearMonth % 12) / 6) * 6) + getBaseMonth();
DateUnit start = new DateUnit( dateUnit );
start.setDay( 1 );
start.setMonth( 1 );
- start = getCalendar().plusMonths( start, months );
- start.setDayOfWeek( getCalendar().weekday( start ) );
+ start = calendar.plusMonths( start, months );
+ start.setDayOfWeek( calendar.weekday( start ) );
DateUnit end = new DateUnit( start );
- end = getCalendar().plusMonths( end, 5 );
- end.setDay( getCalendar().daysInMonth( end.getYear(), end.getMonth() ) );
- end.setDayOfWeek( getCalendar().weekday( end ) );
+ end = calendar.plusMonths( end, 5 );
+ end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
+ end.setDayOfWeek( calendar.weekday( end ) );
return toIsoPeriod( start, end );
}
@@ -95,19 +98,23 @@
@Override
public Period getNextPeriod( Period period )
{
- DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
- dateUnit = getCalendar().plusMonths( dateUnit, 6 );
+ Calendar cal = getCalendar();
+
+ DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
+ dateUnit = cal.plusMonths( dateUnit, 6 );
- return createPeriod( getCalendar().toIso( dateUnit ) );
+ return createPeriod( cal.toIso( dateUnit ), cal );
}
@Override
public Period getPreviousPeriod( Period period )
{
- DateUnit dateUnit = getCalendar().fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
- dateUnit = getCalendar().minusMonths( dateUnit, 6 );
+ Calendar cal = getCalendar();
+
+ DateUnit dateUnit = cal.fromIso( DateUnit.fromJdkDate( period.getStartDate() ) );
+ dateUnit = cal.minusMonths( dateUnit, 6 );
- return createPeriod( getCalendar().toIso( dateUnit ) );
+ return createPeriod( cal.toIso( dateUnit ), cal );
}
/**
@@ -117,7 +124,9 @@
@Override
public List<Period> generatePeriods( DateUnit dateUnit )
{
- Period period = createPeriod( dateUnit );
+ Calendar cal = getCalendar();
+
+ Period period = createPeriod( dateUnit, cal );
dateUnit = createLocalDateUnitInstance( period.getStartDate() );
List<Period> periods = Lists.newArrayList();
@@ -162,12 +171,14 @@
@Override
public Date getRewindedDate( Date date, Integer rewindedPeriods )
{
+ Calendar cal = getCalendar();
+
date = date != null ? date : new Date();
rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
DateUnit dateUnit = createLocalDateUnitInstance( date );
- getCalendar().minusMonths( dateUnit, rewindedPeriods * 6 );
+ cal.minusMonths( dateUnit, rewindedPeriods * 6 );
- return getCalendar().toIso( dateUnit ).toJdkDate();
+ return cal.toIso( dateUnit ).toJdkDate();
}
}
=== 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 2014-05-21 10:11:13 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/TwoYearlyPeriodType.java 2014-06-23 14:31:05 +0000
@@ -83,7 +83,7 @@
}
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, org.hisp.dhis.calendar.Calendar calendar )
{
return null;
}
=== 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-05-21 11:52:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java 2014-06-23 14:31:05 +0000
@@ -29,6 +29,8 @@
*/
import com.google.common.collect.Lists;
+
+import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateInterval;
import org.hisp.dhis.calendar.DateIntervalType;
import org.hisp.dhis.calendar.DateUnit;
@@ -72,13 +74,13 @@
}
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, Calendar calendar )
{
DateUnit start = new DateUnit( dateUnit );
- start = getCalendar().minusDays( dateUnit, getCalendar().weekday( start ) - 1 );
+ start = calendar.minusDays( dateUnit, getCalendar().weekday( start ) - 1 );
DateUnit end = new DateUnit( start );
- end = getCalendar().plusDays( end, getCalendar().daysInWeek() - 1 );
+ end = calendar.plusDays( end, getCalendar().daysInWeek() - 1 );
return toIsoPeriod( start, end );
}
@@ -96,19 +98,23 @@
@Override
public Period getNextPeriod( Period period )
{
+ Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
- dateUnit = getCalendar().plusWeeks( dateUnit, 1 );
+ dateUnit = cal.plusWeeks( dateUnit, 1 );
- return createPeriod( dateUnit );
+ return createPeriod( dateUnit, cal );
}
@Override
public Period getPreviousPeriod( Period period )
{
+ Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
- dateUnit = getCalendar().minusWeeks( dateUnit, 1 );
+ dateUnit = cal.minusWeeks( dateUnit, 1 );
- return createPeriod( dateUnit );
+ return createPeriod( dateUnit, cal );
}
/**
@@ -141,15 +147,17 @@
@Override
public List<Period> generateRollingPeriods( DateUnit dateUnit )
{
+ Calendar cal = getCalendar();
+
List<Period> periods = Lists.newArrayList();
dateUnit.setMonth( 1 );
- dateUnit = getCalendar().minusDays( dateUnit, getCalendar().weekday( dateUnit ) - 1 );
- dateUnit = getCalendar().minusDays( dateUnit, 357 );
+ dateUnit = cal.minusDays( dateUnit, cal.weekday( dateUnit ) - 1 );
+ dateUnit = cal.minusDays( dateUnit, 357 );
for ( int i = 0; i < 52; i++ )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusWeeks( dateUnit, 1 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusWeeks( dateUnit, 1 );
}
return periods;
@@ -162,9 +170,11 @@
@Override
public String getIsoDate( DateUnit dateUnit )
{
- int week = getCalendar().week( dateUnit );
+ Calendar cal = getCalendar();
+
+ int week = cal.week( dateUnit );
- if ( week == 1 && dateUnit.getMonth() == getCalendar().monthsInYear() )
+ if ( week == 1 && dateUnit.getMonth() == cal.monthsInYear() )
{
dateUnit.setYear( dateUnit.getYear() + 1 );
}
@@ -184,12 +194,14 @@
@Override
public Date getRewindedDate( Date date, Integer rewindedPeriods )
{
+ Calendar cal = getCalendar();
+
date = date != null ? date : new Date();
rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
DateUnit dateUnit = createLocalDateUnitInstance( date );
- dateUnit = getCalendar().minusWeeks( dateUnit, rewindedPeriods );
+ dateUnit = cal.minusWeeks( dateUnit, rewindedPeriods );
- return getCalendar().toIso( dateUnit ).toJdkDate();
+ return cal.toIso( dateUnit ).toJdkDate();
}
}
=== 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-05-21 11:52:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java 2014-06-23 14:31:05 +0000
@@ -29,6 +29,8 @@
*/
import com.google.common.collect.Lists;
+
+import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateUnit;
import java.util.Date;
@@ -69,7 +71,7 @@
}
@Override
- public Period createPeriod( DateUnit dateUnit )
+ public Period createPeriod( DateUnit dateUnit, Calendar calendar )
{
DateUnit start = new DateUnit( dateUnit );
DateUnit end = new DateUnit( dateUnit );
@@ -77,8 +79,8 @@
start.setDay( 1 );
start.setMonth( 1 );
- end.setMonth( getCalendar().monthsInYear() );
- end.setDay( getCalendar().daysInMonth( end.getYear(), end.getMonth() ) );
+ end.setMonth( calendar.monthsInYear() );
+ end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
return toIsoPeriod( start, end );
}
@@ -96,19 +98,23 @@
@Override
public Period getNextPeriod( Period period )
{
+ Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
- dateUnit = getCalendar().plusYears( dateUnit, 1 );
+ dateUnit = cal.plusYears( dateUnit, 1 );
- return createPeriod( dateUnit );
+ return createPeriod( dateUnit, cal );
}
@Override
public Period getPreviousPeriod( Period period )
{
+ Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( period.getStartDate() );
- dateUnit = getCalendar().minusYears( dateUnit, 1 );
+ dateUnit = cal.minusYears( dateUnit, 1 );
- return createPeriod( dateUnit );
+ return createPeriod( dateUnit, cal );
}
/**
@@ -117,7 +123,9 @@
@Override
public List<Period> generatePeriods( DateUnit dateUnit )
{
- dateUnit = getCalendar().minusYears( dateUnit, 5 );
+ Calendar cal = getCalendar();
+
+ dateUnit = cal.minusYears( dateUnit, 5 );
dateUnit.setDay( 1 );
dateUnit.setMonth( 1 );
@@ -125,8 +133,8 @@
for ( int i = 0; i < 11; ++i )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusYears( dateUnit, 1 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusYears( dateUnit, 1 );
}
return periods;
@@ -155,8 +163,10 @@
@Override
public List<Period> generateLast5Years( Date date )
{
+ Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( date );
- dateUnit = getCalendar().minusYears( dateUnit, 4 );
+ dateUnit = cal.minusYears( dateUnit, 4 );
dateUnit.setDay( 1 );
dateUnit.setMonth( 1 );
@@ -164,8 +174,8 @@
for ( int i = 0; i < 5; ++i )
{
- periods.add( createPeriod( dateUnit ) );
- dateUnit = getCalendar().plusYears( dateUnit, 1 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusYears( dateUnit, 1 );
}
return periods;
@@ -186,12 +196,14 @@
@Override
public Date getRewindedDate( Date date, Integer rewindedPeriods )
{
+ Calendar cal = getCalendar();
+
date = date != null ? date : new Date();
rewindedPeriods = rewindedPeriods != null ? rewindedPeriods : 1;
DateUnit dateUnit = createLocalDateUnitInstance( date );
- dateUnit = getCalendar().minusYears( dateUnit, rewindedPeriods );
+ dateUnit = cal.minusYears( dateUnit, rewindedPeriods );
- return getCalendar().toIso( dateUnit ).toJdkDate();
+ return cal.toIso( dateUnit ).toJdkDate();
}
}