← Back to team overview

dhis-mobile-devs team mailing list archive

[Branch ~dhis-mobile-devs/dhis-mobile/lwuit-tracking] Rev 148: support date format dd-mm-yyyy in data entry form

 

------------------------------------------------------------
revno: 148
committer: Long <Long@Long-Laptop>
branch nick: lwuit-tracking
timestamp: Wed 2013-09-11 23:17:08 +0700
message:
  support date format dd-mm-yyyy in data entry form
modified:
  build.xml
  src/org/hisp/dhis/mobile/util/FormUtils.java
  src/org/hisp/dhis/mobile/util/TrackingUtils.java
  src/org/hisp/dhis/mobile/view/TrackingDataEntryView.java


--
lp:~dhis-mobile-devs/dhis-mobile/lwuit-tracking
https://code.launchpad.net/~dhis-mobile-devs/dhis-mobile/lwuit-tracking

Your team DHIS mobile developers is subscribed to branch lp:~dhis-mobile-devs/dhis-mobile/lwuit-tracking.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis-mobile-devs/dhis-mobile/lwuit-tracking/+edit-subscription
=== modified file 'build.xml'
--- build.xml	2013-09-11 15:25:01 +0000
+++ build.xml	2013-09-11 16:17:08 +0000
@@ -34,11 +34,11 @@
 	<!-- Which logo to use -->
 	<property name="logo" value="dhis2_logo.png" />
 	<!-- Server URL -->
-	<property name="server.url" value="http://localhost:9999"; />
+	<property name="server.url" value="http://192.168.137.1:9999"; />
 	<!-- User Name -->
-	<property name="username" value="mobile" />
+	<property name="username" value="long" />
 	<!-- Password -->
-	<property name="password" value="district" />
+	<property name="password" value="District1" />
 	<!-- Server Phone Number -->
 	<property name="server.phonenumber" value="+8494485878" />
 	<!-- Default Locale -->

=== modified file 'src/org/hisp/dhis/mobile/util/FormUtils.java'
--- src/org/hisp/dhis/mobile/util/FormUtils.java	2013-04-02 10:14:23 +0000
+++ src/org/hisp/dhis/mobile/util/FormUtils.java	2013-09-11 16:17:08 +0000
@@ -60,6 +60,26 @@
         }
     }
 
+    public static boolean isStandardDateFormat( String value )
+    {
+        boolean valid = false;
+        try
+        {
+            Calendar cal = Calendar.getInstance();
+            cal.set( Calendar.DATE, Integer.parseInt( value.substring( 0, 2 ) ) );
+            cal.set( Calendar.MONTH, Integer.parseInt( value.substring( 3, 5 ) ) - 1 );
+            cal.set( Calendar.YEAR, Integer.parseInt( value.substring( 6, 10 ) ) );
+
+            cal.getTime();
+            valid = true;
+            return valid;
+        }
+        catch ( Exception ex )
+        {
+            return valid;
+        }
+    }
+
     public static boolean isNumber( String value )
     {
         try

=== modified file 'src/org/hisp/dhis/mobile/util/TrackingUtils.java'
--- src/org/hisp/dhis/mobile/util/TrackingUtils.java	2013-04-18 04:04:51 +0000
+++ src/org/hisp/dhis/mobile/util/TrackingUtils.java	2013-09-11 16:17:08 +0000
@@ -28,17 +28,19 @@
 
 import org.hisp.dhis.mobile.model.ProgramStageDataElement;
 
-
 /**
  * @author Nguyen Kim Lai
- *
+ * 
  * @version TrackingUtils.java 2:16:55 PM Mar 12, 2013 $
  */
 public class TrackingUtils
 {
     static String type;
+
     static String numberType;
+
     static String value;
+
     public static String getTypeViolation( ProgramStageDataElement dataElement )
     {
         value = dataElement.getValue();
@@ -66,33 +68,43 @@
             }
             else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_DATE ) )
             {
-                if ( !FormUtils.isDate( value ) )
+                // if ( !FormUtils.isDate( value ) )
+                // {
+                // return "is_invalid_date";
+                // }
+
+                // Support standard date format
+                if ( !FormUtils.isStandardDateFormat( value ) )
                 {
                     return "is_invalid_date";
                 }
             }
-            else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_INT ) && numberType.equals( ProgramStageDataElement.VALUE_TYPE_NUMBER ) )
+            else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_INT )
+                && numberType.equals( ProgramStageDataElement.VALUE_TYPE_NUMBER ) )
             {
                 if ( !FormUtils.isNumber( value ) )
                 {
                     return "is_invalid_number";
                 }
             }
-            else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_INT ) && numberType.equals( ProgramStageDataElement.VALUE_TYPE_INT ) )
+            else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_INT )
+                && numberType.equals( ProgramStageDataElement.VALUE_TYPE_INT ) )
             {
                 if ( !FormUtils.isInteger( value ) )
                 {
                     return "is_invalid_integer";
                 }
             }
-            else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_INT ) && numberType.equals( ProgramStageDataElement.VALUE_TYPE_POSITIVE_INT ) )
+            else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_INT )
+                && numberType.equals( ProgramStageDataElement.VALUE_TYPE_POSITIVE_INT ) )
             {
                 if ( !FormUtils.isPositiveInteger( value ) )
                 {
                     return "is_invalid_positive_integer";
                 }
             }
-            else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_INT ) && numberType.equals( ProgramStageDataElement.VALUE_TYPE_NEGATIVE_INT ) )
+            else if ( type.equals( ProgramStageDataElement.VALUE_TYPE_INT )
+                && numberType.equals( ProgramStageDataElement.VALUE_TYPE_NEGATIVE_INT ) )
             {
                 if ( !FormUtils.isNegativeInteger( value ) )
                 {
@@ -102,20 +114,20 @@
         }
         return null;
     }
-    
+
     public static String getUrlForSelectionAll( String url )
     {
         String result;
         char c = '/';
         String backup = url.substring( url.lastIndexOf( c ) );
         result = url.substring( 0, url.lastIndexOf( c ) );
-        result = result.substring( 0, result.lastIndexOf( c )+1 );
-        result = result+"0"+backup;
-        
+        result = result.substring( 0, result.lastIndexOf( c ) + 1 );
+        result = result + "0" + backup;
+
         backup = null;
         url = null;
-        
+
         return result;
     }
-    
+
 }

=== modified file 'src/org/hisp/dhis/mobile/view/TrackingDataEntryView.java'
--- src/org/hisp/dhis/mobile/view/TrackingDataEntryView.java	2013-09-10 07:17:17 +0000
+++ src/org/hisp/dhis/mobile/view/TrackingDataEntryView.java	2013-09-11 16:17:08 +0000
@@ -373,7 +373,9 @@
             }
             else if ( de.getViolatedMessage().equalsIgnoreCase( "is_invalid_date" ) )
             {
-                lblError.setText( "YYYY-mm-dd" );
+                // lblError.setText( "YYYY-mm-dd" );
+                // change to support standard date format
+                lblError.setText( "dd-mm-yyyy" );
             }
             else if ( de.getViolatedMessage().equalsIgnoreCase( "is_invalid_number" ) )
             {