dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20932
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9783: Fixed incorrectly reported year of first weekly period of the year
------------------------------------------------------------
revno: 9783
committer: Bob Jolliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-02-11 12:02:26 +0000
message:
Fixed incorrectly reported year of first weekly period of the year
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 2012-07-23 16:26:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java 2013-02-11 12:02:26 +0000
@@ -228,7 +228,10 @@
cal.setFirstDayOfWeek(Calendar.MONDAY);
int year = cal.get( Calendar.YEAR);
int week = cal.get( Calendar.WEEK_OF_YEAR);
+ int month = cal.get( Calendar.MONTH);
+ if (week == 1 && month == Calendar.DECEMBER) ++year;
+
String periodString = year + "W" + week;
return periodString;
}
=== 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 2012-03-16 18:28:34 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/period/WeeklyPeriodTypeTest.java 2013-02-11 12:02:26 +0000
@@ -95,21 +95,15 @@
cal.clear();
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, 14 );
-
assertEquals( cal.getTime(), period.getStartDate() );
}
@@ -120,7 +114,11 @@
cal.set( 2011, 0, 3 ); // Wednesday
WeeklyPeriodType wpt = new WeeklyPeriodType();
Period p = wpt.createPeriod( cal.getTime() );
- assertEquals( p.getIsoDate(), "2011W1");
+ assertEquals( "2011W1", p.getIsoDate());
+
+ cal.set( 2012, 11, 31 ); // Monday
+ p = wpt.createPeriod( cal.getTime() );
+ assertEquals( "2013W1", p.getIsoDate());
}
@Test