dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31934
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16318: Period structure resource table, fixed issue with no of days column
------------------------------------------------------------
revno: 16318
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-08-05 13:19:29 +0200
message:
Period structure resource table, fixed issue with no of days column
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.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/Period.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java 2014-04-14 12:24:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java 2014-08-05 11:19:29 +0000
@@ -38,6 +38,8 @@
import org.hisp.dhis.common.adapter.JacksonPeriodTypeSerializer;
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
+import org.joda.time.DateTime;
+import org.joda.time.Days;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
@@ -206,7 +208,7 @@
}
/**
- * Return the potential number of periods of the given period type which is
+ * Returns the potential number of periods of the given period type which is
* spanned by this period.
*
* @param type the period type.
@@ -220,6 +222,18 @@
return (int) Math.floor( no );
}
+ /**
+ * Returns the number of days in the period, i.e. the days between the start
+ * and end date.
+ *
+ * @return number of days in period.
+ */
+ public int getDaysInPeriod()
+ {
+ Days days = Days.daysBetween( new DateTime( startDate ), new DateTime( endDate ) );
+ return days.getDays() + 1;
+ }
+
// -------------------------------------------------------------------------
// hashCode, equals and toString
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/MonthlyPeriodTypeTest.java 2014-08-05 11:19:29 +0000
@@ -92,8 +92,19 @@
testCal.set( period2.getStartDate());
assertEquals( 2010, testCal.get( Calendar.YEAR) );
- assertEquals( 0, testCal.get( Calendar.MONTH) );
-
+ assertEquals( 0, testCal.get( Calendar.MONTH) );
+ }
+
+ @Test
+ public void testGetDaysInPeriod()
+ {
+ Period pA = periodType.createPeriod( "20040315" );
+ Period pB = periodType.createPeriod( "201403" );
+ Period pC = periodType.createPeriod( "2014Q2" );
+
+ assertEquals( 1, pA.getDaysInPeriod() );
+ assertEquals( 31, pB.getDaysInPeriod() );
+ assertEquals( 91, pC.getDaysInPeriod() );
}
@Test
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2014-06-27 08:38:40 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2014-08-05 11:19:29 +0000
@@ -492,7 +492,7 @@
values.add( period.getId() );
values.add( period.getIsoDate() );
- values.add( rowType.getFrequencyOrder() );
+ values.add( period.getDaysInPeriod() );
for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
{
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java 2014-07-25 07:56:49 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java 2014-08-05 11:19:29 +0000
@@ -225,8 +225,8 @@
return false;
}
- if ( (startDate.before( baseDate ) || startDate.equals( baseDate ))
- && (endDate.after( baseDate ) || endDate.equals( baseDate )) )
+ if ( ( startDate.before( baseDate ) || startDate.equals( baseDate ) )
+ && ( endDate.after( baseDate ) || endDate.equals( baseDate ) ) )
{
return true;
}