dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31099
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15815: Period types, performance improvements
------------------------------------------------------------
revno: 15815
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-06-23 16:46:45 +0200
message:
Period types, performance improvements
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/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/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-06-23 14:31:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/BiMonthlyPeriodType.java 2014-06-23 14:46:45 +0000
@@ -73,7 +73,7 @@
end = calendar.plusMonths( end, 1 );
end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
- return toIsoPeriod( start, end );
+ return toIsoPeriod( start, end, calendar );
}
@Override
=== 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-06-23 14:31:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialPeriodType.java 2014-06-23 14:46:45 +0000
@@ -78,7 +78,7 @@
end = getCalendar().plusYears( end, 1 );
end = getCalendar().minusDays( end, 1 );
- return toIsoPeriod( start, end );
+ return toIsoPeriod( start, end, calendar );
}
@Override
@@ -94,19 +94,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, null );
+ 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, null );
+ return createPeriod( dateUnit, cal );
}
/**
@@ -116,17 +120,19 @@
@Override
public List<Period> generatePeriods( DateUnit dateUnit )
{
+ Calendar cal = getCalendar();
+
boolean past = dateUnit.getMonth() >= (getBaseMonth() + 1);
List<Period> periods = Lists.newArrayList();
- dateUnit = getCalendar().minusYears( dateUnit, past ? 5 : 6 );
+ dateUnit = cal.minusYears( dateUnit, past ? 5 : 6 );
dateUnit.setMonth( getBaseMonth() + 1 );
dateUnit.setDay( 1 );
for ( int i = 0; i < 11; i++ )
{
- periods.add( createPeriod( dateUnit, null ) );
+ periods.add( createPeriod( dateUnit, cal ) );
dateUnit = getCalendar().plusYears( dateUnit, 1 );
}
@@ -152,19 +158,21 @@
@Override
public List<Period> generateLast5Years( Date date )
{
+ Calendar cal = getCalendar();
+
DateUnit dateUnit = createLocalDateUnitInstance( date );
boolean past = dateUnit.getMonth() >= (getBaseMonth() + 1);
List<Period> periods = Lists.newArrayList();
- dateUnit = getCalendar().minusYears( dateUnit, past ? 4 : 5 );
+ dateUnit = cal.minusYears( dateUnit, past ? 4 : 5 );
dateUnit.setMonth( getBaseMonth() + 1 );
dateUnit.setDay( 1 );
for ( int i = 0; i < 5; i++ )
{
- periods.add( createPeriod( dateUnit, null ) );
- dateUnit = getCalendar().plusYears( dateUnit, 1 );
+ periods.add( createPeriod( dateUnit, cal ) );
+ dateUnit = cal.plusYears( dateUnit, 1 );
}
return periods;
@@ -173,12 +181,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();
}
}
=== 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-06-23 14:31:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java 2014-06-23 14:46:45 +0000
@@ -80,7 +80,7 @@
DateUnit end = new DateUnit( dateUnit );
end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
- return toIsoPeriod( start, end );
+ return toIsoPeriod( start, end, calendar );
}
@Override
=== 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-06-23 14:31:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2014-06-23 14:46:45 +0000
@@ -232,13 +232,20 @@
public Period toIsoPeriod( DateUnit start, DateUnit end )
{
- return new Period( this, getCalendar().toIso( start ).toJdkDate(), getCalendar().toIso( end ).toJdkDate() );
+ org.hisp.dhis.calendar.Calendar cal = getCalendar();
+
+ return new Period( this, cal.toIso( start ).toJdkDate(), cal.toIso( end ).toJdkDate() );
}
+ protected Period toIsoPeriod( DateUnit start, DateUnit end, org.hisp.dhis.calendar.Calendar calendar )
+ {
+ return new Period( this, calendar.toIso( start ).toJdkDate(), calendar.toIso( end ).toJdkDate() );
+ }
+
public Period toIsoPeriod( DateUnit dateUnit )
{
return toIsoPeriod( dateUnit, dateUnit );
- }
+ }
public abstract Period createPeriod( DateUnit dateUnit, org.hisp.dhis.calendar.Calendar calendar );
@@ -269,7 +276,9 @@
*/
public static Calendar createCalendarInstance()
{
- return getCalendar().toIso( getCalendar().today() ).toJdkCalendar();
+ org.hisp.dhis.calendar.Calendar cal = getCalendar();
+
+ return cal.toIso( cal.today() ).toJdkCalendar();
}
/**
@@ -384,8 +393,10 @@
return null;
}
- final DateUnit from = getCalendar().toIso( dateInterval.getFrom() );
- final DateUnit to = getCalendar().toIso( dateInterval.getTo() );
+ org.hisp.dhis.calendar.Calendar cal = getCalendar();
+
+ final DateUnit from = cal.toIso( dateInterval.getFrom() );
+ final DateUnit to = cal.toIso( dateInterval.getTo() );
return new Period( this, from.toJdkDate(), to.toJdkDate() );
}
=== 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-06-23 14:31:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java 2014-06-23 14:46:45 +0000
@@ -82,7 +82,7 @@
end = calendar.plusMonths( end, 2 );
end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
- return toIsoPeriod( start, end );
+ return toIsoPeriod( start, end, calendar );
}
@Override
=== 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-06-23 14:31:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/SixMonthlyAbstractPeriodType.java 2014-06-23 14:46:45 +0000
@@ -82,7 +82,7 @@
end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
end.setDayOfWeek( calendar.weekday( end ) );
- return toIsoPeriod( start, end );
+ return toIsoPeriod( start, end, calendar );
}
@Override
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java 2014-06-23 14:31:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java 2014-06-23 14:46:45 +0000
@@ -77,12 +77,12 @@
public Period createPeriod( DateUnit dateUnit, Calendar calendar )
{
DateUnit start = new DateUnit( dateUnit );
- start = calendar.minusDays( dateUnit, getCalendar().weekday( start ) - 1 );
+ start = calendar.minusDays( dateUnit, calendar.weekday( start ) - 1 );
DateUnit end = new DateUnit( start );
- end = calendar.plusDays( end, getCalendar().daysInWeek() - 1 );
+ end = calendar.plusDays( end, calendar.daysInWeek() - 1 );
- return toIsoPeriod( start, end );
+ return toIsoPeriod( start, end, calendar );
}
@Override
@@ -124,17 +124,19 @@
@Override
public List<Period> generatePeriods( DateUnit dateUnit )
{
+ Calendar cal = getCalendar();
+
List<Period> periods = Lists.newArrayList();
// rewind to start of week
- dateUnit = getCalendar().minusDays( dateUnit, getCalendar().weekday( dateUnit ) - 1 );
+ dateUnit = cal.minusDays( dateUnit, cal.weekday( dateUnit ) - 1 );
- for ( int i = 0; i < getCalendar().weeksInYear( dateUnit.getYear() ); i++ )
+ for ( int i = 0; i < cal.weeksInYear( dateUnit.getYear() ); i++ )
{
- DateInterval interval = getCalendar().toInterval( dateUnit, DateIntervalType.ISO8601_WEEK );
+ DateInterval interval = cal.toInterval( dateUnit, DateIntervalType.ISO8601_WEEK );
periods.add( new Period( this, interval.getFrom().toJdkDate(), interval.getTo().toJdkDate() ) );
- dateUnit = getCalendar().plusWeeks( dateUnit, 1 );
+ dateUnit = cal.plusWeeks( dateUnit, 1 );
}
return periods;
=== 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-06-23 14:31:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/YearlyPeriodType.java 2014-06-23 14:46:45 +0000
@@ -82,7 +82,7 @@
end.setMonth( calendar.monthsInYear() );
end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) );
- return toIsoPeriod( start, end );
+ return toIsoPeriod( start, end, calendar );
}
@Override