dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39070
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19823: proper start of year implemention, uses chronology where possible, and understands leap years
------------------------------------------------------------
revno: 19823
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-08-24 10:20:05 +0700
message:
proper start of year implemention, uses chronology where possible, and understands leap years
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java
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/NepaliCalendar.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.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/AbstractCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java 2015-08-19 07:55:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java 2015-08-24 03:20:05 +0000
@@ -259,8 +259,8 @@
}
@Override
- public DateTimeUnit startOfYear()
+ public DateTimeUnit isoStartOfYear( int year )
{
- return new DateTimeUnit( 0, 1, 1 );
+ return new DateTimeUnit( year, 1, 1 );
}
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java 2015-08-19 07:55:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java 2015-08-24 03:20:05 +0000
@@ -406,5 +406,5 @@
*
* @return
*/
- DateTimeUnit startOfYear();
+ DateTimeUnit isoStartOfYear( int year );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java 2015-08-24 03:20:05 +0000
@@ -41,7 +41,7 @@
*/
public abstract class ChronologyBasedCalendar extends AbstractCalendar
{
- private final Chronology chronology;
+ protected final Chronology chronology;
protected ChronologyBasedCalendar( Chronology chronology )
{
@@ -313,4 +313,11 @@
DateTime dateTime = dateTimeUnit.toJodaDateTime( chronology );
return DateTimeUnit.fromJodaDateTime( dateTime.minusYears( years ), dateTimeUnit.isIso8601() );
}
+
+ @Override
+ public DateTimeUnit isoStartOfYear( int year )
+ {
+ DateTime dateTime = new DateTime( year, 1, 1, 0, 0, chronology ).withChronology( ISOChronology.getInstance() );
+ return DateTimeUnit.fromJodaDateTime( dateTime );
+ }
}
=== 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 02:40:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/EthiopianCalendar.java 2015-08-24 03:20:05 +0000
@@ -30,7 +30,6 @@
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;
@@ -58,10 +57,4 @@
{
return "ethiopian";
}
-
- @Override
- public DateTimeUnit startOfYear()
- {
- return new DateTimeUnit( 0, 9, 11 );
- }
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java 2015-08-19 07:55:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java 2015-08-24 03:20:05 +0000
@@ -484,7 +484,7 @@
}
@Override
- public DateTimeUnit startOfYear()
+ public DateTimeUnit isoStartOfYear( int year )
{
return startIso;
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java 2015-08-19 08:08:11 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java 2015-08-24 03:20:05 +0000
@@ -57,7 +57,7 @@
public static Period getPeriod( Calendar calendar, Integer year )
{
- DateTimeUnit startOfYear = calendar.startOfYear();
+ DateTimeUnit startOfYear = calendar.isoStartOfYear( year );
DateTime time = new DateTime( year, startOfYear.getMonth(), startOfYear.getDay(), 1, 1 );
return PERIODTYPE.createPeriod( time.toDate() );