← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3341: more thorough enforcement of iso week numbering + additional tests

 

------------------------------------------------------------
revno: 3341
committer: Bob Joliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-04-11 12:59:53 +0100
message:
  more thorough enforcement of iso week numbering + additional tests
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.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/WeeklyPeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2011-02-24 21:01:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java	2011-04-11 11:59:53 +0000
@@ -191,6 +191,8 @@
     public String getIsoDate( Period period )
     {
         Calendar cal = createCalendarInstance( period.getStartDate() );
+        cal.setMinimalDaysInFirstWeek(4);
+        cal.setFirstDayOfWeek(Calendar.MONDAY);
         int year = cal.get( Calendar.YEAR);
         int week = cal.get( Calendar.WEEK_OF_YEAR);
 
@@ -205,9 +207,12 @@
         int week = Integer.parseInt( isoDate.substring( 5 ) );
         
         Calendar cal = Calendar.getInstance();
+        cal.clear();
+        cal.setMinimalDaysInFirstWeek(4);
+        cal.setFirstDayOfWeek( Calendar.MONDAY );
+
         cal.set( Calendar.YEAR, year );
         cal.set( Calendar.WEEK_OF_YEAR, week );
-        cal.setFirstDayOfWeek( Calendar.MONDAY );
 
         return createPeriod( cal.getTime() );
     }

=== 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	2011-02-27 21:10:14 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java	2011-04-11 11:59:53 +0000
@@ -99,24 +99,40 @@
     }
 
     @Test
-    @Ignore //TODO fix this test seems to fail for different people, might be related to locale
     public void isoDates()
     {
         WeeklyPeriodType weekly = new WeeklyPeriodType();
         Calendar cal = Calendar.getInstance();
+
         cal.clear();
 
-        cal.set( 2010, 11, 27 );
-
-        Period period = weekly.createPeriod( "2011W1" );
+        cal.set( 2008, 11, 29 );
+
+        Period period = weekly.createPeriod( "2009W1" );
+
+        assertEquals(cal.getTime(), period.getStartDate());
+
+        cal.set( 2011, 0, 3 );
+
+        period = weekly.createPeriod( "2011W1" );
 
         assertEquals(cal.getTime(), period.getStartDate());
 
         period = weekly.createPeriod( "2011W11" );
 
-        cal.set( 2011, 2, 7 );
+        cal.set( 2011, 2, 14 );
 
         assertEquals(cal.getTime(), period.getStartDate());
 
     }
+
+    @Test
+    public void getIsoDate()
+    {
+        Calendar cal = Calendar.getInstance();
+        cal.set( 2011, 0, 3 ); // Wednesday
+        WeeklyPeriodType wpt = new WeeklyPeriodType();
+        Period p = wpt.createPeriod( cal.getTime() );
+        assertEquals( p.getIsoDate(), "2011W1");
+    }
 }