← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4003: [DHISMobile]Mobile send date (instead week text) to server, it will be converted to WeeklyPeriod ...

 

------------------------------------------------------------
revno: 4003
committer: trannguyenminhluan trannguyenminhluan@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2011-06-23 15:56:44 +0700
message:
  [DHISMobile]Mobile send date (instead week text) to server, it will be converted to WeeklyPeriod (for weekly form).
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/PeriodUtil.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-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/PeriodUtil.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/PeriodUtil.java	2011-02-15 12:55:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/utils/PeriodUtil.java	2011-06-23 08:56:44 +0000
@@ -67,17 +67,31 @@
 
         if ( periodType instanceof WeeklyPeriodType )
         {
-            int dashIndex = periodName.indexOf( '-' );
-
-            if ( dashIndex < 0 )
-            {
-                return null;
-            }
-
-            int week = Integer.parseInt( periodName.substring( 0, dashIndex ) );
-            int year = Integer.parseInt( periodName.substring( dashIndex + 1, periodName.length() ) );
-
-            return periodType.createPeriod(year + "W" + week);
+        	String pattern = "yyyy-MM-dd";
+            SimpleDateFormat formatter = new SimpleDateFormat( pattern );
+            Date date;
+            try
+            {
+                date = formatter.parse( periodName );
+            }
+            catch ( ParseException e )
+            {
+                throw new IllegalArgumentException( "Couldn't make a period of type " + periodType.getName()
+                    + " and name " + periodName, e );
+            }
+            return periodType.createPeriod( date );
+            
+//            int dashIndex = periodName.indexOf( '-' );
+//
+//            if ( dashIndex < 0 )
+//            {
+//                return null;
+//            }
+//
+//            int week = Integer.parseInt( periodName.substring( 0, dashIndex ) );
+//            int year = Integer.parseInt( periodName.substring( dashIndex + 1, periodName.length() ) );
+//
+//            return periodType.createPeriod(year + "W" + week);
         }
 
         if ( periodType instanceof MonthlyPeriodType )