------------------------------------------------------------ revno: 19830 committer: Morten Olav Hansen <morte...@gmail.com> branch nick: dhis2 timestamp: Mon 2015-08-24 15:48:49 +0700 message: bugfixes for chronology based quarterly period types modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopianCalendar.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/QuarterlyPeriodType.java dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/impl/EthiopianCalendarTest.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/calendar/impl/EthiopianCalendar.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopianCalendar.java 2015-08-24 03:47:48 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopianCalendar.java 2015-08-24 08:48:49 +0000 @@ -30,10 +30,13 @@ import org.hisp.dhis.calendar.Calendar; import org.hisp.dhis.calendar.ChronologyBasedCalendar; +import org.hisp.dhis.calendar.DateTimeUnit; import org.joda.time.DateTimeZone; import org.joda.time.chrono.EthiopicChronology; import org.springframework.stereotype.Component; +import java.util.Date; + /** * @author Morten Olav Hansen <morte...@gmail.com> */ @@ -59,6 +62,25 @@ } @Override + public DateTimeUnit toIso( DateTimeUnit dateTimeUnit ) + { + dateTimeUnit = normalize( dateTimeUnit ); + return super.toIso( dateTimeUnit ); + } + + @Override + public DateTimeUnit fromIso( Date date ) + { + return super.fromIso( date ); + } + + @Override + public DateTimeUnit fromIso( DateTimeUnit dateTimeUnit ) + { + return super.fromIso( dateTimeUnit ); + } + + @Override public int daysInMonth( int year, int month ) { if ( month < 12 ) @@ -68,4 +90,18 @@ return 30 + super.daysInMonth( year, 13 ); } + + private DateTimeUnit normalize( DateTimeUnit dateTimeUnit ) + { + if ( dateTimeUnit.getMonth() < 12 || dateTimeUnit.getDay() <= 30 ) + { + return dateTimeUnit; + } + + dateTimeUnit = new DateTimeUnit( dateTimeUnit ); + dateTimeUnit.setDay( dateTimeUnit.getDay() - 30 ); + dateTimeUnit.setMonth( 13 ); + + return dateTimeUnit; + } } === 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 2015-06-11 21:37:27 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/MonthlyPeriodType.java 2015-08-24 08:48:49 +0000 @@ -52,7 +52,7 @@ private static final long serialVersionUID = -6920058214699654387L; private static final String ISO_FORMAT = "yyyyMM"; - + private static final String ISO8601_DURATION = "P1M"; /** @@ -78,6 +78,12 @@ DateTimeUnit start = new DateTimeUnit( dateTimeUnit ); start.setDay( 1 ); + if ( start.getMonth() > 12 ) + { + start.setYear( start.getYear() + 1 ); + start.setMonth( 1 ); + } + DateTimeUnit end = new DateTimeUnit( dateTimeUnit ); end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) ); @@ -173,9 +179,9 @@ } @Override - public String getIso8601Duration() + public String getIso8601Duration() { - return ISO8601_DURATION; + return ISO8601_DURATION; } === 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 2015-08-24 07:46:44 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java 2015-08-24 08:48:49 +0000 @@ -80,6 +80,12 @@ start.setMonth( ((dateTimeUnit.getMonth() - 1) - ((dateTimeUnit.getMonth() - 1) % 3)) + 1 ); start.setDay( 1 ); + if ( start.getMonth() > 12 ) + { + start.setYear( start.getYear() + 1 ); + start.setMonth( 1 ); + } + DateTimeUnit end = new DateTimeUnit( start ); end = calendar.plusMonths( end, 2 ); end.setDay( calendar.daysInMonth( end.getYear(), end.getMonth() ) ); === modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/impl/EthiopianCalendarTest.java' --- dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/impl/EthiopianCalendarTest.java 2015-08-24 07:46:44 +0000 +++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/impl/EthiopianCalendarTest.java 2015-08-24 08:48:49 +0000 @@ -32,6 +32,7 @@ import org.hisp.dhis.calendar.DateTimeUnit; import org.hisp.dhis.period.Cal; import org.hisp.dhis.period.DailyPeriodType; +import org.hisp.dhis.period.MonthlyPeriodType; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.QuarterlyPeriodType; import org.junit.Before; @@ -93,13 +94,23 @@ } @Test - @Ignore public void testGenerateQuarterlyPeriods() { Date startDate = new Cal( 1975, 1, 1, true ).time(); - Date endDate = new Cal( 1976, 1, 2, true ).time(); + Date endDate = new Cal( 2025, 1, 2, true ).time(); List<Period> quarters = new QuarterlyPeriodType().generatePeriods( calendar, startDate, endDate ); - assertEquals( 5, quarters.size() ); + assertEquals( 201, quarters.size() ); + } + + @Test + @Ignore + public void testGenerateMonthlyPeriods() + { + Date startDate = new Cal( 1975, 1, 1, true ).time(); + Date endDate = new Cal( 2025, 1, 2, true ).time(); + + List<Period> monthly = new MonthlyPeriodType().generatePeriods( calendar, startDate, endDate ); + assertEquals( 601, monthly.size() ); } }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp