dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17339
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6857: Impl generateRollingPeriods on WeeklyPeriodType
------------------------------------------------------------
revno: 6857
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-05-04 14:02:34 +0200
message:
Impl generateRollingPeriods on WeeklyPeriodType
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.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/WeeklyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java 2012-02-13 11:41:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java 2012-05-04 12:02:34 +0000
@@ -128,8 +128,8 @@
public List<Period> generatePeriods( Period period )
{
Calendar cal = createCalendarInstance( period.getStartDate() );
- cal.setMinimalDaysInFirstWeek(4);
- cal.setFirstDayOfWeek(Calendar.MONDAY);
+ cal.setMinimalDaysInFirstWeek( 4 );
+ cal.setFirstDayOfWeek( Calendar.MONDAY );
// ---------------------------------------------------------------------
// If the supplied period is the first week of a year where the start
@@ -154,6 +154,28 @@
return generatePeriods( cal );
}
+ /**
+ * Generates the last 12 months where the last one is the month
+ * which the given date is inside.
+ */
+ public List<Period> generateRollingPeriods( Date date )
+ {
+ Calendar cal = createCalendarInstance( date );
+ cal.setFirstDayOfWeek( Calendar.MONDAY );
+ cal.set( Calendar.DAY_OF_WEEK, Calendar.MONDAY );
+ cal.add( Calendar.DAY_OF_YEAR, -357 );
+
+ ArrayList<Period> periods = new ArrayList<Period>();
+
+ for ( int i = 0; i < 52; i++ )
+ {
+ periods.add( createPeriod( cal ) );
+ cal.add( Calendar.DAY_OF_YEAR, 1 );
+ }
+
+ return periods;
+ }
+
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------