← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16597: Use LocalDate instead of DateTime in ChronologyBasedCalendar, helps with any tz issues since the ...

 

------------------------------------------------------------
revno: 16597
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-09-01 13:16:29 +0700
message:
  Use LocalDate instead of DateTime in ChronologyBasedCalendar, helps with any tz issues since the methods there are not time based anyways (number of days in week, month, year etc).
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.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/ChronologyBasedCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java	2014-08-29 15:45:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/ChronologyBasedCalendar.java	2014-09-01 06:16:29 +0000
@@ -30,6 +30,7 @@
 
 import org.joda.time.Chronology;
 import org.joda.time.DateTime;
+import org.joda.time.LocalDate;
 import org.joda.time.chrono.ISOChronology;
 
 /**
@@ -189,36 +190,36 @@
     @Override
     public int monthsInYear()
     {
-        DateTime dateTime = new DateTime( 1, 1, 1, 12, 0, chronology );
-        return dateTime.monthOfYear().getMaximumValue();
+        LocalDate localDate = new LocalDate( 1, 1, 1, chronology );
+        return localDate.toDateTimeAtStartOfDay().monthOfYear().getMaximumValue();
     }
 
     @Override
     public int daysInWeek()
     {
-        DateTime dateTime = new DateTime( 1, 1, 1, 12, 0, chronology );
-        return dateTime.dayOfWeek().getMaximumValue();
+        LocalDate localDate = new LocalDate( 1, 1, 1, chronology );
+        return localDate.toDateTimeAtStartOfDay().dayOfWeek().getMaximumValue();
     }
 
     @Override
     public int daysInYear( int year )
     {
-        DateTime dateTime = new DateTime( year, 1, 1, 12, 0, chronology );
-        return (int) dateTime.year().toInterval().toDuration().getStandardDays();
+        LocalDate localDate = new LocalDate( year, 1, 1, chronology );
+        return (int) localDate.toDateTimeAtStartOfDay().year().toInterval().toDuration().getStandardDays();
     }
 
     @Override
     public int daysInMonth( int year, int month )
     {
-        DateTime dateTime = new DateTime( year, month, 1, 12, 0, chronology );
-        return dateTime.dayOfMonth().getMaximumValue();
+        LocalDate localDate = new LocalDate( year, month, 1, chronology );
+        return localDate.toDateTimeAtStartOfDay().dayOfMonth().getMaximumValue();
     }
 
     @Override
     public int weeksInYear( int year )
     {
-        DateTime dateTime = new DateTime( year, 1, 1, 12, 0, chronology );
-        return dateTime.weekOfWeekyear().getMaximumValue();
+        LocalDate localDate = new LocalDate( year, 1, 1, chronology );
+        return localDate.toDateTimeAtStartOfDay().weekOfWeekyear().getMaximumValue();
     }
 
     @Override

=== 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	2014-08-29 10:02:21 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2014-09-01 06:16:29 +0000
@@ -61,7 +61,7 @@
 public abstract class PeriodType
     implements Serializable
 {
-    // cache for speeding up period lookup, uses calendar.name() + periodType.getName() + date.toString() as key
+    // cache for speeding up 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 )