dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #10623
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2910: Minor fix to FinancialAprilPeriodType
------------------------------------------------------------
revno: 2910
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-02-24 17:28:30 +0100
message:
Minor fix to FinancialAprilPeriodType
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialAprilPeriodTypeTest.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/FinancialAprilPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java 2011-02-15 06:22:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/FinancialAprilPeriodType.java 2011-02-24 16:28:30 +0000
@@ -46,6 +46,8 @@
public static final String NAME = "FinancialApril";
public static final int FREQUENCY_ORDER = 365;
+
+ private static final int BASE_MONTH = Calendar.APRIL;
// -------------------------------------------------------------------------
// PeriodType functionality
@@ -71,8 +73,10 @@
private Period createPeriod( Calendar cal )
{
- cal.set( Calendar.YEAR, cal.get( Calendar.YEAR ) + cal.get( Calendar.MONDAY ) / 7 - 1);
- cal.set( Calendar.MONTH, Calendar.APRIL );
+ boolean past = cal.get( Calendar.MONTH ) >= BASE_MONTH;
+
+ cal.set( Calendar.YEAR, past ? cal.get( Calendar.YEAR ) : cal.get( Calendar.YEAR ) - 1 );
+ cal.set( Calendar.MONTH, BASE_MONTH );
cal.set( Calendar.DATE, 1 );
Date startDate = cal.getTime();
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialAprilPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialAprilPeriodTypeTest.java 2010-11-17 10:58:45 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/FinancialAprilPeriodTypeTest.java 2011-02-24 16:28:30 +0000
@@ -32,6 +32,7 @@
import java.util.Calendar;
import java.util.List;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -40,24 +41,31 @@
public class FinancialAprilPeriodTypeTest
{
+ private Calendar startCal;
+ private Calendar endCal;
+ private FinancialAprilPeriodType periodType;
+
+ @Before
+ public void before()
+ {
+ startCal = PeriodType.createCalendarInstance();
+ endCal = PeriodType.createCalendarInstance();
+ periodType = new FinancialAprilPeriodType();
+ }
+
@Test
public void testCreatePeriod()
{
- FinancialAprilPeriodType periodType = new FinancialAprilPeriodType();
-
Calendar testCal = PeriodType.createCalendarInstance();
testCal.set( 2009, Calendar.FEBRUARY, 15 );
- Calendar startCal = PeriodType.createCalendarInstance();
startCal.set( 2008, Calendar.APRIL, 1 );
- Calendar endCal = PeriodType.createCalendarInstance();
endCal.set( 2009, Calendar.MARCH, 31 );
Period period = periodType.createPeriod( testCal.getTime() );
assertEquals( startCal.getTime(), period.getStartDate() );
assertEquals( endCal.getTime(), period.getEndDate() );
-
testCal.set( 2009, Calendar.SEPTEMBER, 12 );
@@ -73,16 +81,12 @@
@Test
public void testGeneratePeriods()
{
- FinancialAprilPeriodType periodType = new FinancialAprilPeriodType();
-
Calendar testCal = PeriodType.createCalendarInstance();
testCal.set( 2009, 1, 15 );
List<Period> periods = periodType.generatePeriods( testCal.getTime() );
- Calendar startCal = PeriodType.createCalendarInstance();
startCal.set( 1998, Calendar.APRIL, 1 );
- Calendar endCal = PeriodType.createCalendarInstance();
endCal.set( 1999, Calendar.MARCH, 31 );
Period startPeriod = periods.get( 0 );
@@ -97,6 +101,5 @@
Period endPeriod = periods.get( periods.size() - 1 );
assertEquals( startCal.getTime(), endPeriod.getStartDate() );
assertEquals( endCal.getTime(), endPeriod.getEndDate() );
-
}
}