← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17096: Replace Calendar class with Joda time in test classes.

 

------------------------------------------------------------
revno: 17096
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-10-14 12:46:33 +0700
message:
  Replace Calendar class with Joda time in test classes.
modified:
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodStoreTest.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/crosstab/CrossTabServiceTest.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionServiceTest.java
  dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStoreTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramInstanceServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramInstanceStoreTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramStageInstanceServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramStageInstanceStoreTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStoreTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueServiceTest.java
  dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueStoreTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java	2014-05-21 08:17:58 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java	2014-10-14 05:46:33 +0000
@@ -28,16 +28,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeConstants;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.List;
-
-import static org.junit.Assert.*;
-
 /**
  * @author Bob Jolliffe
  * @version $Id$
@@ -56,16 +59,18 @@
     @Ignore
     public void testGeneratePeriods()
     {
-        Calendar testCal = Calendar.getInstance();
+        DateTime testDate = new DateTime();
+        
         WeeklyPeriodType wpt = new WeeklyPeriodType();
 
         for ( int year = 1990; year < 2020; year++ )
         {
             for ( int day = -7; day < 7; day++ )
-            {
-                testCal.set( year, 0, 1 ); // 1st day of year
-                testCal.add( Calendar.DATE, day );
-                Period p1 = wpt.createPeriod( testCal.getTime() );
+            { 
+                testDate = new DateTime( year, 1, 1, 0, 0); // 1st day of year
+                testDate = testDate.minusDays( day );
+                
+                Period p1 = wpt.createPeriod( testDate.toDate() );
                 List<Period> generatedPeriods = wpt.generatePeriods( p1 );
                 assertTrue( "Period " + p1 + " in generated set", generatedPeriods.contains( p1 ) );
             }
@@ -74,56 +79,49 @@
 
     @Test
     public void testCreatePeriod()
-    {
-        Calendar testCal = Calendar.getInstance();
-        Calendar startCal = Calendar.getInstance();
-        Calendar endCal = Calendar.getInstance();
-
-        // arbitrary instance - should increase coverage
-        testCal.set( 2009, 4, 27 ); // Wednesday
+    {   
+        DateTime testDate = new DateTime( 2009, 4, 27, 0, 0 );
         WeeklyPeriodType wpt = new WeeklyPeriodType();
-
-        Period p = wpt.createPeriod( testCal.getTime() );
-        startCal.setTime( p.getStartDate() );
-        endCal.setTime( p.getEndDate() );
-
-        assertFalse( "start date after given date", startCal.after( testCal ) );
-        assertFalse( "end date before given date", endCal.before( testCal ) );
-
-        assertTrue( startCal.get( Calendar.DAY_OF_WEEK ) == Calendar.MONDAY );
-        assertTrue( endCal.get( Calendar.DAY_OF_WEEK ) == Calendar.SUNDAY );
-
+        Period p = wpt.createPeriod( testDate.toDate() );
+        
+        DateTime startDate = new DateTime( 2009, 4, 27, 0, 0 );
+        DateTime endDate = new DateTime( 2009, 5, 3, 0, 0 );
+
+        assertFalse( "start date after given date", startDate.isAfter(  p.getStartDate().getTime() ) );
+        assertFalse( "end date before given date", endDate.isAfter( p.getEndDate().getTime() ) );
+        
+
+      assertTrue( startDate.getDayOfWeek() == DateTimeConstants.MONDAY );
+      assertTrue( endDate.getDayOfWeek() == DateTimeConstants.SUNDAY  );
     }
 
     @Test
     public void isoDates()
     {
-        Calendar cal = Calendar.getInstance();
-        cal.clear();
-
-        cal.set( 2008, 11, 29 );
+        DateTime testDate = new DateTime( 2008, 12, 29, 0, 0 );
+        
         Period period = periodType.createPeriod( "2009W1" );
-        assertEquals( cal.getTime(), period.getStartDate() );
+        assertEquals( testDate.toDate(), period.getStartDate() );
 
-        cal.set( 2011, 0, 3 );
+        testDate = new DateTime( 2011, 1, 3, 0, 0 );
         period = periodType.createPeriod( "2011W1" );
-        assertEquals( cal.getTime(), period.getStartDate() );
+        assertEquals( testDate.toDate(), period.getStartDate() );
 
+        testDate = new DateTime( 2011, 3, 14, 0, 0 );
         period = periodType.createPeriod( "2011W11" );
-        cal.set( 2011, 2, 14 );
-        assertEquals( cal.getTime(), period.getStartDate() );
+        assertEquals( testDate.toDate(), period.getStartDate() );
     }
 
     @Test
     public void getIsoDate()
     {
-        Calendar cal = Calendar.getInstance();
-        cal.set( 2011, 0, 3 ); // Wednesday
-        Period p = periodType.createPeriod( cal.getTime() );
+        DateTime testDate = new DateTime( 2011, 1, 3, 0, 0 );
+        
+        Period p = periodType.createPeriod( testDate.toDate() );
         assertEquals( "2011W1", p.getIsoDate() );
 
-        cal.set( 2012, 11, 31 ); // Monday
-        p = periodType.createPeriod( cal.getTime() );
+        testDate = new DateTime( 2012, 12, 31, 0, 0 ); // Monday
+        p = periodType.createPeriod( testDate.toDate() );
         assertEquals( "2013W1", p.getIsoDate() );
     }
 
@@ -172,18 +170,19 @@
     @Test
     public void testGetIsoDate()
     {
-        Calendar calendar = Calendar.getInstance();
-
-        calendar.set( 2012, Calendar.DECEMBER, 31 );
-        assertEquals( "2013W1", periodType.getIsoDate( new Period( periodType, calendar.getTime(), calendar.getTime() ) ) );
-
-        calendar.set( 2012, Calendar.DECEMBER, 30 );
-        assertEquals( "2012W52", periodType.getIsoDate( new Period( periodType, calendar.getTime(), calendar.getTime() ) ) );
-
-        calendar.set( 2009, Calendar.DECEMBER, 29 );
-        assertEquals( "2009W53", periodType.getIsoDate( new Period( periodType, calendar.getTime(), calendar.getTime() ) ) );
-
-        calendar.set( 2010, Calendar.JANUARY, 4 );
-        assertEquals( "2010W1", periodType.getIsoDate( new Period( periodType, calendar.getTime(), calendar.getTime() ) ) );
+//        Calendar calendar = Calendar.getInstance();
+        
+        DateTime testDate = new DateTime(2012, 12, 31, 0, 0);
+
+        assertEquals( "2013W1", periodType.getIsoDate( new Period( periodType, testDate.toDate(), testDate.toDate() ) ) );
+
+        testDate = new DateTime(2012, 12, 30, 0, 0);
+        assertEquals( "2012W52", periodType.getIsoDate( new Period( periodType, testDate.toDate(), testDate.toDate() ) ) );
+
+        testDate = new DateTime(2009, 12, 29, 0, 0);
+        assertEquals( "2009W53", periodType.getIsoDate( new Period( periodType, testDate.toDate(), testDate.toDate() ) ) );
+
+        testDate = new DateTime(2010, 1, 4, 0, 0);
+        assertEquals( "2010W1", periodType.getIsoDate( new Period( periodType, testDate.toDate(), testDate.toDate() ) ) );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodServiceTest.java	2014-10-07 13:46:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodServiceTest.java	2014-10-14 05:46:33 +0000
@@ -65,8 +65,8 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         int idA = periodService.addPeriod( periodA );
         int idB = periodService.addPeriod( periodB );
@@ -76,15 +76,15 @@
         assertNotNull( periodA );
         assertEquals( idA, periodA.getId() );
         assertEquals( periodTypeA, periodA.getPeriodType() );
-        assertEquals( getDay( 0 ), periodA.getStartDate() );
-        assertEquals( getDay( 1 ), periodA.getEndDate() );
+        assertEquals( getDay( 1 ), periodA.getStartDate() );
+        assertEquals( getDay( 2 ), periodA.getEndDate() );
 
         periodB = periodService.getPeriod( idB );
         assertNotNull( periodB );
         assertEquals( idB, periodB.getId() );
         assertEquals( periodTypeA, periodB.getPeriodType() );
-        assertEquals( getDay( 1 ), periodB.getStartDate() );
-        assertEquals( getDay( 2 ), periodB.getEndDate() );
+        assertEquals( getDay( 2 ), periodB.getStartDate() );
+        assertEquals( getDay( 3 ), periodB.getEndDate() );
 
         periodC = periodService.getPeriod( idC );
         assertNotNull( periodC );
@@ -102,8 +102,8 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2  ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
         int idA = periodService.addPeriod( periodA );
@@ -149,8 +149,8 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
     
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
         Period periodE = new Period( periodTypeA, getDay( 3 ), getDay( 4 ) );
@@ -160,19 +160,19 @@
         int idD = periodService.addPeriod( periodD );
         int idE = periodService.addPeriod( periodE );
     
-        periodA = periodService.getPeriod( getDay( 0 ), getDay( 1 ), periodTypeA );
+        periodA = periodService.getPeriod( getDay( 1 ), getDay( 2 ), periodTypeA );
         assertNotNull( periodA );
         assertEquals( idA, periodA.getId() );
         assertEquals( periodTypeA, periodA.getPeriodType() );
-        assertEquals( getDay( 0 ), periodA.getStartDate() );
-        assertEquals( getDay( 1 ), periodA.getEndDate() );
+        assertEquals( getDay( 1 ), periodA.getStartDate() );
+        assertEquals( getDay( 2 ), periodA.getEndDate() );
         
-        periodB = periodService.getPeriod( getDay( 1 ), getDay( 2 ), periodTypeA );
+        periodB = periodService.getPeriod( getDay( 2 ), getDay( 3 ), periodTypeA );
         assertNotNull( periodB );
         assertEquals( idB, periodB.getId() );
         assertEquals( periodTypeA, periodB.getPeriodType() );
-        assertEquals( getDay( 1 ), periodB.getStartDate() );
-        assertEquals( getDay( 2 ), periodB.getEndDate() );
+        assertEquals( getDay( 2 ), periodB.getStartDate() );
+        assertEquals( getDay( 3 ), periodB.getEndDate() );
     
         periodC = periodService.getPeriod( getDay( 2 ), getDay( 3 ), periodTypeB );
         assertNotNull( periodC );
@@ -196,8 +196,8 @@
         assertEquals( getDay( 4 ), periodE.getEndDate() );
         
         assertNull( periodService.getPeriod( getDay( 1 ), getDay( 2 ), periodTypeB ) );
-        assertNull( periodService.getPeriod( getDay( 2 ), getDay( 3 ), periodTypeA ) );
-        assertNull( periodService.getPeriod( getDay( 0 ), getDay( 5 ), periodTypeB ) );
+        assertNull( periodService.getPeriod( getDay( 4 ), getDay( 5 ), periodTypeA ) );
+        assertNull( periodService.getPeriod( getDay( 1 ), getDay( 5 ), periodTypeB ) );
         assertNull( periodService.getPeriod( getDay( 4 ), getDay( 3 ), periodTypeB ) );
         assertNull( periodService.getPeriod( getDay( 5 ), getDay( 6 ), periodTypeA ) );
     }
@@ -207,9 +207,9 @@
     {
         PeriodType periodType = periodService.getAllPeriodTypes().iterator().next();
 
-        Period periodA = new Period( periodType, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodType, getDay( 1 ), getDay( 2 ) );
-        Period periodC = new Period( periodType, getDay( 2 ), getDay( 3 ) );
+        Period periodA = new Period( periodType, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodType, getDay( 2 ), getDay( 3 ) );
+        Period periodC = new Period( periodType, getDay( 3 ), getDay( 4 ) );
         
         periodService.addPeriod( periodA );
         periodService.addPeriod( periodB );
@@ -232,8 +232,8 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
         periodService.addPeriod( periodA );
@@ -241,23 +241,23 @@
         periodService.addPeriod( periodC );
         periodService.addPeriod( periodD );
 
-        Collection<Period> periods = periodService.getPeriodsBetweenDates( getDay( 0 ), getDay( 0 ) );
+        Collection<Period> periods = periodService.getPeriodsBetweenDates( getDay( 1 ), getDay( 1 ) );
         assertNotNull( periods );
         assertEquals( 0, periods.size() );
 
-        periods = periodService.getPeriodsBetweenDates( getDay( 0 ), getDay( 1 ) );
+        periods = periodService.getPeriodsBetweenDates( getDay( 1 ), getDay( 2 ) );
         assertNotNull( periods );
         assertEquals( 1, periods.size() );
         assertEquals( periodA, periods.iterator().next() );
 
-        periods = periodService.getPeriodsBetweenDates( getDay( 1 ), getDay( 4 ) );
+        periods = periodService.getPeriodsBetweenDates( getDay( 2 ), getDay( 4 ) );
         assertNotNull( periods );
         assertEquals( 3, periods.size() );
         assertTrue( periods.contains( periodB ) );
         assertTrue( periods.contains( periodC ) );
         assertTrue( periods.contains( periodD ) );
 
-        periods = periodService.getPeriodsBetweenDates( getDay( 0 ), getDay( 5 ) );
+        periods = periodService.getPeriodsBetweenDates( getDay( 1 ), getDay( 5 ) );
         assertNotNull( periods );
         assertEquals( 4, periods.size() );
         assertTrue( periods.contains( periodA ) );
@@ -349,7 +349,7 @@
     {
         PeriodType type = periodService.getAllPeriodTypes().iterator().next();
         
-        Period periodA = new Period( type, getDay( 0 ), getDay( 2 ) );
+        Period periodA = new Period( type, getDay( 1 ), getDay( 2 ) );
         Period periodB = new Period( type, getDay( 2 ), getDay( 4 ) );
         Period periodC = new Period( type, getDay( 4 ), getDay( 6 ) );
         Period periodD = new Period( type, getDay( 6 ), getDay( 8 ) );
@@ -394,9 +394,9 @@
         PeriodType periodTypeB = it.next();
         PeriodType periodTypeC = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
-        Period periodC = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
+        Period periodC = new Period( periodTypeA, getDay( 3 ), getDay( 4 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
         periodService.addPeriod( periodA );
         periodService.addPeriod( periodB );
@@ -491,7 +491,7 @@
         Period basePeriod = new Period( periodType, getDay( 8 ), getDay( 20 ) );
         
         Collection<Period> inclusivePeriods = periodService.getInclusivePeriods( basePeriod, periods );
-        
+
         assertTrue( inclusivePeriods.size() == 4 );
         assertTrue( inclusivePeriods.contains( periodB ) );
         assertTrue( inclusivePeriods.contains( periodC ) );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodStoreTest.java	2014-10-07 13:46:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/period/PeriodStoreTest.java	2014-10-14 05:46:33 +0000
@@ -65,8 +65,8 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         int idA = periodStore.addPeriod( periodA );
         int idB = periodStore.addPeriod( periodB );
@@ -76,15 +76,15 @@
         assertNotNull( periodA );
         assertEquals( idA, periodA.getId() );
         assertEquals( periodTypeA, periodA.getPeriodType() );
-        assertEquals( getDay( 0 ), periodA.getStartDate() );
-        assertEquals( getDay( 1 ), periodA.getEndDate() );
+        assertEquals( getDay( 1 ), periodA.getStartDate() );
+        assertEquals( getDay( 2 ), periodA.getEndDate() );
 
         periodB = periodStore.get( idB );
         assertNotNull( periodB );
         assertEquals( idB, periodB.getId() );
         assertEquals( periodTypeA, periodB.getPeriodType() );
-        assertEquals( getDay( 1 ), periodB.getStartDate() );
-        assertEquals( getDay( 2 ), periodB.getEndDate() );
+        assertEquals( getDay( 2 ), periodB.getStartDate() );
+        assertEquals( getDay( 3 ), periodB.getEndDate() );
 
         periodC = periodStore.get( idC );
         assertNotNull( periodC );
@@ -103,8 +103,8 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
         int idA = periodStore.addPeriod( periodA );
@@ -151,8 +151,8 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
         Period periodE = new Period( periodTypeA, getDay( 3 ), getDay( 4 ) );
@@ -162,19 +162,19 @@
         int idD = periodStore.addPeriod( periodD );
         int idE = periodStore.addPeriod( periodE );
 
-        periodA = periodStore.getPeriod( getDay( 0 ), getDay( 1 ), periodTypeA );
+        periodA = periodStore.getPeriod( getDay( 1 ), getDay( 2 ), periodTypeA );
         assertNotNull( periodA );
         assertEquals( idA, periodA.getId() );
         assertEquals( periodTypeA, periodA.getPeriodType() );
-        assertEquals( getDay( 0 ), periodA.getStartDate() );
-        assertEquals( getDay( 1 ), periodA.getEndDate() );
+        assertEquals( getDay( 1 ), periodA.getStartDate() );
+        assertEquals( getDay( 2 ), periodA.getEndDate() );
         
-        periodB = periodStore.getPeriod( getDay( 1 ), getDay( 2 ), periodTypeA );
+        periodB = periodStore.getPeriod( getDay( 2 ), getDay( 3 ), periodTypeA );
         assertNotNull( periodB );
         assertEquals( idB, periodB.getId() );
         assertEquals( periodTypeA, periodB.getPeriodType() );
-        assertEquals( getDay( 1 ), periodB.getStartDate() );
-        assertEquals( getDay( 2 ), periodB.getEndDate() );
+        assertEquals( getDay( 2 ), periodB.getStartDate() );
+        assertEquals( getDay( 3 ), periodB.getEndDate() );
 
         periodC = periodStore.getPeriod( getDay( 2 ), getDay( 3 ), periodTypeB );
         assertNotNull( periodC );
@@ -198,8 +198,8 @@
         assertEquals( getDay( 4 ), periodE.getEndDate() );
         
         assertNull( periodStore.getPeriod( getDay( 1 ), getDay( 2 ), periodTypeB ) );
-        assertNull( periodStore.getPeriod( getDay( 2 ), getDay( 3 ), periodTypeA ) );
-        assertNull( periodStore.getPeriod( getDay( 0 ), getDay( 5 ), periodTypeB ) );
+        assertNull( periodStore.getPeriod( getDay( 1 ), getDay( 3 ), periodTypeA ) );
+        assertNull( periodStore.getPeriod( getDay( 1 ), getDay( 5 ), periodTypeB ) );
         assertNull( periodStore.getPeriod( getDay( 4 ), getDay( 3 ), periodTypeB ) );
         assertNull( periodStore.getPeriod( getDay( 5 ), getDay( 6 ), periodTypeA ) );
     }
@@ -210,7 +210,7 @@
     {
         PeriodType periodType = periodStore.getAllPeriodTypes().iterator().next();
 
-        Period periodA = new Period( periodType, getDay( 0 ), getDay( 1 ) );
+        Period periodA = new Period( periodType, getDay( 1 ), getDay( 1 ) );
         Period periodB = new Period( periodType, getDay( 1 ), getDay( 2 ) );
         Period periodC = new Period( periodType, getDay( 2 ), getDay( 3 ) );
         
@@ -236,8 +236,8 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
         periodStore.addPeriod( periodA );
@@ -245,23 +245,23 @@
         periodStore.addPeriod( periodC );
         periodStore.addPeriod( periodD );
 
-        Collection<Period> periods = periodStore.getPeriodsBetweenDates( getDay( 0 ), getDay( 0 ) );
+        Collection<Period> periods = periodStore.getPeriodsBetweenDates( getDay( 1 ), getDay( 1 ) );
         assertNotNull( periods );
         assertEquals( 0, periods.size() );
 
-        periods = periodStore.getPeriodsBetweenDates( getDay( 0 ), getDay( 1 ) );
+        periods = periodStore.getPeriodsBetweenDates( getDay( 1), getDay( 2 ) );
         assertNotNull( periods );
         assertEquals( 1, periods.size() );
         assertEquals( periodA, periods.iterator().next() );
 
-        periods = periodStore.getPeriodsBetweenDates( getDay( 1 ), getDay( 4 ) );
+        periods = periodStore.getPeriodsBetweenDates( getDay( 2 ), getDay( 4 ) );
         assertNotNull( periods );
         assertEquals( 3, periods.size() );
         assertTrue( periods.contains( periodB ) );
         assertTrue( periods.contains( periodC ) );
         assertTrue( periods.contains( periodD ) );
 
-        periods = periodStore.getPeriodsBetweenDates( getDay( 0 ), getDay( 5 ) );
+        periods = periodStore.getPeriodsBetweenDates( getDay( 1 ), getDay( 5 ) );
         assertNotNull( periods );
         assertEquals( 4, periods.size() );
         assertTrue( periods.contains( periodA ) );
@@ -279,37 +279,37 @@
         PeriodType periodTypeA = it.next();
         PeriodType periodTypeB = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
         Period periodC = new Period( periodTypeB, getDay( 2 ), getDay( 3 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
-        Period periodE = new Period( periodTypeB, getDay( 0 ), getDay( 4 ) );
+        Period periodE = new Period( periodTypeB, getDay( 1 ), getDay( 4 ) );
         periodStore.addPeriod( periodA );
         periodStore.addPeriod( periodB );
         periodStore.addPeriod( periodC );
         periodStore.addPeriod( periodD );
         periodStore.addPeriod( periodE );
 
-        Collection<Period> periods = periodStore.getPeriodsBetweenOrSpanningDates( getDay( 0 ), getDay( 0 ) );
-        assertNotNull( periods );
-        assertEquals( 2, periods.size() );
-        assertTrue( periods.contains( periodA ) );
-        assertTrue( periods.contains( periodE ) );
-
-        periods = periodStore.getPeriodsBetweenOrSpanningDates( getDay( 0 ), getDay( 1 ) );
-        assertNotNull( periods );
-        assertEquals( 2, periods.size() );
-        assertTrue( periods.contains( periodA ) );
-        assertTrue( periods.contains( periodE ) );
-
-        periods = periodStore.getPeriodsBetweenOrSpanningDates( getDay( 1 ), getDay( 3 ) );
+        Collection<Period> periods = periodStore.getPeriodsBetweenOrSpanningDates( getDay( 1 ), getDay( 1 ) );
+        assertNotNull( periods );
+        assertEquals( 2, periods.size() );
+        assertTrue( periods.contains( periodA ) );
+        assertTrue( periods.contains( periodE ) );
+
+        periods = periodStore.getPeriodsBetweenOrSpanningDates( getDay( 1 ), getDay( 2 ) );
+        assertNotNull( periods );
+        assertEquals( 2, periods.size() );
+        assertTrue( periods.contains( periodA ) );
+        assertTrue( periods.contains( periodE ) );
+
+        periods = periodStore.getPeriodsBetweenOrSpanningDates( getDay( 2 ), getDay( 3 ) );
         assertNotNull( periods );
         assertEquals( 3, periods.size() );
         assertTrue( periods.contains( periodB ) );
         assertTrue( periods.contains( periodC ) );
         assertTrue( periods.contains( periodE ) );
 
-        periods = periodStore.getPeriodsBetweenOrSpanningDates( getDay( 1 ), getDay( 4 ) );
+        periods = periodStore.getPeriodsBetweenOrSpanningDates( getDay( 2 ), getDay( 4 ) );
         assertNotNull( periods );
         assertEquals( 4, periods.size() );
         assertTrue( periods.contains( periodB ) );
@@ -402,7 +402,7 @@
     {
         PeriodType type = periodStore.getAllPeriodTypes().iterator().next();
         
-        Period periodA = new Period( type, getDay( 0 ), getDay( 2 ) );
+        Period periodA = new Period( type, getDay( 1 ), getDay( 2 ) );
         Period periodB = new Period( type, getDay( 2 ), getDay( 4 ) );
         Period periodC = new Period( type, getDay( 4 ), getDay( 6 ) );
         Period periodD = new Period( type, getDay( 6 ), getDay( 8 ) );
@@ -448,9 +448,9 @@
         PeriodType periodTypeB = it.next();
         PeriodType periodTypeC = it.next();
 
-        Period periodA = new Period( periodTypeA, getDay( 0 ), getDay( 1 ) );
-        Period periodB = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
-        Period periodC = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
+        Period periodA = new Period( periodTypeA, getDay( 1 ), getDay( 2 ) );
+        Period periodB = new Period( periodTypeA, getDay( 2 ), getDay( 3 ) );
+        Period periodC = new Period( periodTypeA, getDay( 3 ), getDay( 4 ) );
         Period periodD = new Period( periodTypeB, getDay( 3 ), getDay( 4 ) );
         periodStore.addPeriod( periodA );
         periodStore.addPeriod( periodB );

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/crosstab/CrossTabServiceTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/crosstab/CrossTabServiceTest.java	2014-10-07 13:46:29 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/crosstab/CrossTabServiceTest.java	2014-10-14 05:46:33 +0000
@@ -28,10 +28,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -62,6 +63,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.WeeklyPeriodType;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -108,13 +110,11 @@
     @Override
     public void setUpTest()
     { 
-        Calendar calendar = Calendar.getInstance();
-        
-        calendar.set( 2007, 0, 1 );
+        DateTime testDate = new DateTime(2007, 1, 1, 0 , 0);
         
         WeeklyPeriodType periodType = (WeeklyPeriodType) periodService.getPeriodTypeByName( WeeklyPeriodType.NAME );
         
-        Period period = createPeriod( periodType, calendar.getTime(), calendar.getTime() );
+        Period period = createPeriod( periodType, testDate.toDate(), testDate.toDate() );
 
         generatedPeriods = periodType.generatePeriods( period ).iterator();
         

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionServiceTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionServiceTest.java	2014-10-14 05:46:33 +0000
@@ -33,7 +33,6 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
@@ -69,6 +68,7 @@
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -253,10 +253,9 @@
         // Program Instance && data values
         // ---------------------------------------------------------------------
 
-        Calendar today = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( today );
+        DateTime today = DateTime.now();
         ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, program,
-            today.getTime(), today.getTime(), organisationUnit );
+            today.toDate(), today.toDate(), organisationUnit );
 
         ProgramStageInstance stageInstanceA = programStageInstanceService.getProgramStageInstance( programInstance,
             stageA );
@@ -280,8 +279,8 @@
         PeriodType periodType = periodService.getPeriodTypeByName( DailyPeriodType.NAME );
         period = new Period();
         period.setPeriodType( periodType );
-        period.setStartDate( today.getTime() );
-        period.setEndDate( today.getTime() );
+        period.setStartDate( today.toDate() );
+        period.setEndDate( today.toDate() );
         periodService.addPeriod( period );
 
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStoreTest.java'
--- dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStoreTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-eventreporting/src/test/java/org/hisp/dhis/caseaggregation/CaseAggregationConditionStoreTest.java	2014-10-14 05:46:33 +0000
@@ -31,7 +31,6 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
@@ -67,6 +66,7 @@
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValue;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -250,10 +250,10 @@
         // Program Instance && data values
         // ---------------------------------------------------------------------
 
-        Calendar today = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( today );
-        ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, program, today.getTime(),
-            today.getTime(), organisationUnit );
+        DateTime today = DateTime.now();
+        today.withTimeAtStartOfDay();
+        ProgramInstance programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, program, today.toDate(),
+            today.toDate(), organisationUnit );
 
         ProgramStageInstance stageInstanceA = programStageInstanceService.getProgramStageInstance( programInstance,
             stageA );
@@ -277,8 +277,8 @@
         PeriodType periodType = periodService.getPeriodTypeByName( DailyPeriodType.NAME );
         period = new Period();
         period.setPeriodType( periodType );
-        period.setStartDate( today.getTime() );
-        period.setEndDate( today.getTime() );
+        period.setStartDate( today.toDate() );
+        period.setEndDate( today.toDate() );
         periodService.addPeriod( period );
 
         // ---------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramIndicatorServiceTest.java	2014-10-14 05:46:33 +0000
@@ -33,7 +33,6 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
@@ -43,11 +42,11 @@
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
 import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -125,14 +124,14 @@
         TrackedEntityInstance entityInstance = createTrackedEntityInstance( 'A', organisationUnit );
         entityInstanceService.addTrackedEntityInstance( entityInstance );
 
-        Calendar calIncident = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calIncident );
-        calIncident.add( Calendar.DATE, -70 );
-        incidenDate = calIncident.getTime();
-
-        Calendar calEnrollment = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calEnrollment );
-        enrollmentDate = calEnrollment.getTime();
+        DateTime testDate1 = DateTime.now();
+        testDate1.withTimeAtStartOfDay();
+        testDate1 = testDate1.minusDays( 70 );
+        incidenDate = testDate1.toDate();
+        
+        DateTime testDate2 = DateTime.now();
+        testDate2.withTimeAtStartOfDay();
+        enrollmentDate = testDate2.toDate();
 
         programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, programA, enrollmentDate, incidenDate,
             organisationUnit );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramInstanceServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramInstanceServiceTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramInstanceServiceTest.java	2014-10-14 05:46:33 +0000
@@ -33,7 +33,6 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
@@ -42,13 +41,13 @@
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.sms.config.SmsConfigurationManager;
 import org.hisp.dhis.trackedentity.TrackedEntityAttributeService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -171,14 +170,14 @@
         TrackedEntityInstance entityInstanceB = createTrackedEntityInstance( 'B', organisationUnitB );
         entityInstanceService.addTrackedEntityInstance( entityInstanceB );
 
-        Calendar calIncident = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calIncident );
-        calIncident.add( Calendar.DATE, -70 );
-        incidenDate = calIncident.getTime();
-
-        Calendar calEnrollment = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calEnrollment );
-        enrollmentDate = calEnrollment.getTime();
+        DateTime testDate1 = DateTime.now();
+        testDate1.withTimeAtStartOfDay();
+        testDate1 = testDate1.minusDays( 70 );
+        incidenDate = testDate1.toDate();
+        
+        DateTime testDate2 = DateTime.now();
+        testDate2.withTimeAtStartOfDay();
+        enrollmentDate = testDate2.toDate();
 
         programInstanceA = new ProgramInstance( enrollmentDate, incidenDate, entityInstanceA, programA );
         programInstanceA.setUid( "UID-A" );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramInstanceStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramInstanceStoreTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramInstanceStoreTest.java	2014-10-14 05:46:33 +0000
@@ -31,7 +31,6 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
@@ -40,10 +39,10 @@
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.JdbcTemplate;
@@ -157,14 +156,14 @@
         TrackedEntityInstance entityInstanceB = createTrackedEntityInstance( 'B', organisationUnitB );
         entityInstanceService.addTrackedEntityInstance( entityInstanceB );
 
-        Calendar calIncident = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calIncident );
-        calIncident.add( Calendar.DATE, -70 );
-        incidenDate = calIncident.getTime();
-
-        Calendar calEnrollment = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calEnrollment );
-        enrollmentDate = calEnrollment.getTime();
+        DateTime testDate1 = DateTime.now();
+        testDate1.withTimeAtStartOfDay();
+        testDate1 = testDate1.minusDays( 70 );
+        incidenDate = testDate1.toDate();
+        
+        DateTime testDate2 = DateTime.now();
+        testDate2.withTimeAtStartOfDay();
+        enrollmentDate = testDate2.toDate();
 
         programInstanceA = new ProgramInstance( enrollmentDate, incidenDate, entityInstanceA, programA );
         programInstanceA.setUid( "UID-A" );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramStageInstanceServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramStageInstanceServiceTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramStageInstanceServiceTest.java	2014-10-14 05:46:33 +0000
@@ -33,7 +33,6 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
@@ -47,7 +46,6 @@
 import org.hisp.dhis.mock.MockI18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.sms.config.BulkSmsGatewayConfig;
 import org.hisp.dhis.sms.config.SmsConfiguration;
 import org.hisp.dhis.sms.config.SmsConfigurationManager;
@@ -58,6 +56,7 @@
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
 import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValueService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -265,14 +264,14 @@
          * Program Instance and Program Stage Instance
          */
 
-        Calendar calIncident = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calIncident );
-        calIncident.add( Calendar.DATE, -70 );
-        incidenDate = calIncident.getTime();
-
-        Calendar calEnrollment = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calEnrollment );
-        enrollmentDate = calEnrollment.getTime();
+        DateTime testDate1 = DateTime.now();
+        testDate1.withTimeAtStartOfDay();
+        testDate1 = testDate1.minusDays( 70 );
+        incidenDate = testDate1.toDate();
+        
+        DateTime testDate2 = DateTime.now();
+        testDate2.withTimeAtStartOfDay();
+        enrollmentDate = testDate2.toDate();
 
         programInstanceA = new ProgramInstance( enrollmentDate, incidenDate, entityInstanceA, programA );
         programInstanceA.setUid( "UID-PIA" );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramStageInstanceStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramStageInstanceStoreTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/program/ProgramStageInstanceStoreTest.java	2014-10-14 05:46:33 +0000
@@ -47,6 +47,7 @@
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceReminder;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -228,14 +229,14 @@
          * Program Instance and Program Stage Instance
          */
 
-        Calendar calIncident = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calIncident );
-        calIncident.add( Calendar.DATE, -70 );
-        incidenDate = calIncident.getTime();
-
-        Calendar calEnrollment = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( calEnrollment );
-        enrollmentDate = calEnrollment.getTime();
+        DateTime testDate1 = DateTime.now();
+        testDate1.withTimeAtStartOfDay();
+        testDate1 = testDate1.minusDays( 70  );
+        incidenDate = testDate1.toDate();
+        
+        DateTime testDate2 = DateTime.now();
+        testDate2.withTimeAtStartOfDay();
+        enrollmentDate = testDate2.toDate();
 
         programInstanceA = new ProgramInstance( enrollmentDate, incidenDate, entityInstanceA, programA );
         programInstanceA.setUid( "UID-PIA" );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditServiceTest.java	2014-05-27 15:40:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditServiceTest.java	2014-10-14 05:46:33 +0000
@@ -33,14 +33,13 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.PeriodType;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -85,9 +84,9 @@
         entityInstanceB = createTrackedEntityInstance( 'B', organisationUnit );
         entityInstanceService.addTrackedEntityInstance( entityInstanceB );
 
-        Calendar cal = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( cal );
-        today = cal.getTime();
+        DateTime testDate = DateTime.now();
+        testDate.withTimeAtStartOfDay();
+        today = testDate.toDate();
 
         auditA = new TrackedEntityAudit( entityInstanceA, "test", today, TrackedEntityAudit.MODULE_ENTITY_INSTANCE_DASHBOARD );
         auditB = new TrackedEntityAudit( entityInstanceB, "test", today, TrackedEntityAudit.MODULE_ENTITY_INSTANCE_DASHBOARD );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStoreTest.java	2014-05-27 15:40:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentity/TrackedEntityAuditStoreTest.java	2014-10-14 05:46:33 +0000
@@ -31,14 +31,13 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.PeriodType;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -83,9 +82,9 @@
         entityInstanceB = createTrackedEntityInstance( 'B', organisationUnit );
         entityInstanceService.addTrackedEntityInstance( entityInstanceB );
 
-        Calendar cal = Calendar.getInstance();
-        PeriodType.clearTimeOfDay( cal );
-        today = cal.getTime();
+        DateTime testDate = DateTime.now();
+        testDate.withTimeAtStartOfDay();
+        today = testDate.toDate();
 
         auditA = new TrackedEntityAudit( entityInstanceA, "test", today, TrackedEntityAudit.MODULE_ENTITY_INSTANCE_DASHBOARD );
         auditB = new TrackedEntityAudit( entityInstanceB, "test", today, TrackedEntityAudit.MODULE_ENTITY_INSTANCE_DASHBOARD );

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueServiceTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueServiceTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueServiceTest.java	2014-10-14 05:46:33 +0000
@@ -33,7 +33,6 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
@@ -54,6 +53,7 @@
 import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -143,14 +143,17 @@
         programStages.add( stageB );
         program.setProgramStages( programStages );
         programService.updateProgram( program );
-
-        Calendar calYesterday = Calendar.getInstance();
-        calYesterday.add( Calendar.DATE, -1 );
-        yesterday = calYesterday.getTime();
-        Calendar calTomorrow = Calendar.getInstance();
-        calTomorrow.add( Calendar.DATE, 1 );
-        tomorrow = calTomorrow.getTime();
-
+        
+        DateTime yesterDate = DateTime.now();
+        yesterDate.withTimeAtStartOfDay();
+        yesterDate.minusDays( 1 );
+        yesterday = yesterDate.toDate();
+
+        DateTime tomorrowDate = DateTime.now();
+        tomorrowDate.withTimeAtStartOfDay();
+        tomorrowDate.plusDays( 1 );
+        tomorrow = tomorrowDate.toDate();
+        
         programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, program, yesterday, yesterday,
             organisationUnit );
 

=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueStoreTest.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueStoreTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueStoreTest.java	2014-10-14 05:46:33 +0000
@@ -32,7 +32,6 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
@@ -53,6 +52,7 @@
 import org.hisp.dhis.program.ProgramStageService;
 import org.hisp.dhis.trackedentity.TrackedEntityInstance;
 import org.hisp.dhis.trackedentity.TrackedEntityInstanceService;
+import org.joda.time.DateTime;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -144,12 +144,16 @@
         program.setProgramStages( programStages );
         programService.updateProgram( program );
 
-        Calendar calYesterday = Calendar.getInstance();
-        calYesterday.add( Calendar.DATE, -1 );
-        yesterday = calYesterday.getTime();
-        Calendar calTomorrow = Calendar.getInstance();
-        calTomorrow.add( Calendar.DATE, 1 );
-        tomorrow = calTomorrow.getTime();
+         DateTime yesterDate = DateTime.now();
+        yesterDate.withTimeAtStartOfDay();
+        yesterDate.minusDays( 1 );
+        yesterday = yesterDate.toDate();
+
+        DateTime tomorrowDate = DateTime.now();
+        tomorrowDate.withTimeAtStartOfDay();
+        tomorrowDate.plusDays( 1 );
+        tomorrow = tomorrowDate.toDate();
+        
 
         programInstance = programInstanceService.enrollTrackedEntityInstance( entityInstance, program, yesterday, yesterday,
             organisationUnit );

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2014-10-07 13:46:29 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2014-10-14 05:46:33 +0000
@@ -34,7 +34,6 @@
 import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -105,6 +104,7 @@
 import org.hisp.dhis.validation.ValidationCriteria;
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleGroup;
+import org.joda.time.DateTime;
 import org.springframework.aop.framework.Advised;
 import org.springframework.aop.support.AopUtils;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -150,17 +150,14 @@
 
     static
     {
-        Calendar calendar = Calendar.getInstance();
-        calendar.clear();
-        calendar.set( 1970, Calendar.JANUARY, 1 );
-
-        date = calendar.getTime();
+        DateTime dateTime = new DateTime(1970, 1, 1, 0, 0);
+        date = dateTime.toDate();
     }
 
     // -------------------------------------------------------------------------
     // Convenience methods
     // -------------------------------------------------------------------------
-
+    
     /**
      * Creates a date.
      *
@@ -171,14 +168,8 @@
      */
     public static Date getDate( int year, int month, int day )
     {
-        final Calendar calendar = Calendar.getInstance();
-
-        calendar.clear();
-        calendar.set( Calendar.YEAR, year );
-        calendar.set( Calendar.MONTH, month - 1 );
-        calendar.set( Calendar.DAY_OF_MONTH, day );
-
-        return calendar.getTime();
+        DateTime dateTime = new DateTime(year, month, day, 0, 0);
+        return dateTime.toDate();
     }
 
     /**
@@ -189,12 +180,11 @@
      */
     public Date getDay( int day )
     {
-        final Calendar calendar = Calendar.getInstance();
-
-        calendar.clear();
-        calendar.set( Calendar.DAY_OF_YEAR, day );
-
-        return calendar.getTime();
+        DateTime dataTime = DateTime.now();
+        dataTime = dataTime.withTimeAtStartOfDay() ;
+        dataTime = dataTime.withDayOfYear( day );
+
+        return dataTime.toDate();
     }
 
     /**