dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39076
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19829: minor fixes, make sure to use local chronology as basis for PeriodType.toIsoPeriod => getIsoDate
------------------------------------------------------------
revno: 19829
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-08-24 14:46:44 +0700
message:
minor fixes, make sure to use local chronology as basis for PeriodType.toIsoPeriod => getIsoDate
modified:
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/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/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2015-07-15 09:45:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java 2015-08-24 07:46:44 +0000
@@ -62,7 +62,7 @@
implements Serializable
{
// Cache for period lookup, uses calendar.name() + periodType.getName() + date.getTime() as key
-
+
private static Cache<String, Period> periodCache = CacheBuilder.newBuilder()
.expireAfterAccess( 5, TimeUnit.MINUTES )
.initialCapacity( 10000 )
@@ -310,14 +310,14 @@
DateTimeUnit from = calendar.toIso( start );
DateTimeUnit to = calendar.toIso( end );
- return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( from ) );
+ return new Period( this, from.toJdkDate(), to.toJdkDate(), getIsoDate( start ) );
}
public Period toIsoPeriod( DateTimeUnit dateTimeUnit )
{
return toIsoPeriod( dateTimeUnit, dateTimeUnit );
}
-
+
public abstract String getIso8601Duration();
public abstract Period createPeriod( DateTimeUnit dateTimeUnit, org.hisp.dhis.calendar.Calendar calendar );
@@ -456,17 +456,17 @@
public static List<Period> getPeriodsFromIsoStrings( List<String> isoPeriods )
{
List<Period> periods = new ArrayList<>();
-
+
for ( String isoPeriod : isoPeriods )
{
Period period = getPeriodFromIsoString( isoPeriod );
-
+
if ( period != null )
{
periods.add( period );
}
}
-
+
return periods;
}
=== 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-06-11 21:37:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/QuarterlyPeriodType.java 2015-08-24 07:46:44 +0000
@@ -52,7 +52,7 @@
private static final long serialVersionUID = -5973809094923012052L;
private static final String ISO_FORMAT = "yyyyQn";
-
+
private static final String ISO8601_DURATION = "P1Q";
/**
@@ -77,7 +77,7 @@
{
DateTimeUnit start = new DateTimeUnit( dateTimeUnit );
- start.setMonth( ( ( dateTimeUnit.getMonth() - 1 ) - ( ( dateTimeUnit.getMonth() - 1 ) % 3 ) ) + 1 );
+ start.setMonth( ((dateTimeUnit.getMonth() - 1) - ((dateTimeUnit.getMonth() - 1) % 3)) + 1 );
start.setDay( 1 );
DateTimeUnit end = new DateTimeUnit( start );
@@ -147,7 +147,7 @@
public List<Period> generateRollingPeriods( Date date )
{
date = createPeriod( date ).getStartDate();
-
+
return generateRollingPeriods( createLocalDateUnitInstance( date ) );
}
@@ -185,7 +185,7 @@
case 10:
return dateTimeUnit.getYear() + "Q4";
default:
- throw new IllegalArgumentException( "Month not valid [1,4,7,10]" );
+ throw new IllegalArgumentException( "Month not valid [1,4,7,10], was given " + dateTimeUnit.getMonth() );
}
}
@@ -197,11 +197,11 @@
{
return ISO_FORMAT;
}
-
+
@Override
- public String getIso8601Duration()
+ public String getIso8601Duration()
{
- return ISO8601_DURATION;
+ return ISO8601_DURATION;
}
=== 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:03:59 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/calendar/impl/EthiopianCalendarTest.java 2015-08-24 07:46:44 +0000
@@ -33,7 +33,9 @@
import org.hisp.dhis.period.Cal;
import org.hisp.dhis.period.DailyPeriodType;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.QuarterlyPeriodType;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import java.util.Date;
@@ -89,4 +91,15 @@
List<Period> days = new DailyPeriodType().generatePeriods( calendar, startDate, endDate );
assertEquals( 18264, days.size() );
}
+
+ @Test
+ @Ignore
+ public void testGenerateQuarterlyPeriods()
+ {
+ Date startDate = new Cal( 1975, 1, 1, true ).time();
+ Date endDate = new Cal( 1976, 1, 2, true ).time();
+
+ List<Period> quarters = new QuarterlyPeriodType().generatePeriods( calendar, startDate, endDate );
+ assertEquals( 5, quarters.size() );
+ }
}