← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16489: Calendar, performance improvement. In createPeriod, not going through expensive instantiation of ...

 

------------------------------------------------------------
revno: 16489
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-08-24 19:10:16 +0200
message:
  Calendar, performance improvement. In createPeriod, not going through expensive instantiation of gregorian calendar but getting DateUnit directly from Date. in fromJdkDate, avoid instantiating a second DateTime and rather use constructor.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.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/DateUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java	2014-08-22 05:35:40 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/DateUnit.java	2014-08-24 17:10:16 +0000
@@ -238,6 +238,18 @@
     }
 
     /**
+     * Converts from Joda-Time DateTime to DateUnit
+     *
+     * @param dateTime DateTime object
+     * @param iso8601 whether date time is iso8601
+     * @return Populated DateUnit object
+     */
+    public static DateUnit fromDateTime( DateTime dateTime, boolean iso8601 )
+    {
+        return new DateUnit( dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getDayOfWeek(), iso8601 );
+    }
+
+    /**
      * Converts from JDK Calendar to DateUnit
      *
      * @param calendar JDK Calendar object
@@ -257,8 +269,7 @@
      */
     public static DateUnit fromJdkDate( Date date )
     {
-        DateUnit dateUnit = fromDateTime( new DateTime( date.getTime() ) );
-        return new DateUnit( dateUnit, true );
+        return fromDateTime( new DateTime( date.getTime() ), true );
     }
 
     @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-21 07:47:06 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2014-08-24 17:10:16 +0000
@@ -242,9 +242,7 @@
      */
     public Period createPeriod( Date date, org.hisp.dhis.calendar.Calendar calendar )
     {
-        Calendar cal = createCalendarInstance( date );
-        
-        return createPeriod( calendar.fromIso( DateUnit.fromJdkCalendar( cal ) ), calendar );
+        return createPeriod( calendar.fromIso( DateUnit.fromJdkDate( date ) ), calendar );
     }
 
     public Period toIsoPeriod( DateUnit start, DateUnit end )