You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2014/12/11 16:08:49 UTC

svn commit: r1644664 - /commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java

Author: sebb
Date: Thu Dec 11 15:08:49 2014
New Revision: 1644664

URL: http://svn.apache.org/r1644664
Log:
NET-562 FTPFile.toFormattedString should print only signficant parts of the parsed date
Only clear one field as doing re-enables the 'set' status for all others

Modified:
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java?rev=1644664&r1=1644663&r2=1644664&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java Thu Dec 11 15:08:49 2014
@@ -121,20 +121,21 @@ public class FTPTimestampParserImpl impl
 
     /*
      * Sets the Calendar precision (used by FTPFile#toFormattedDate) by clearing
-     * the units which were not in the format used to parse the date
+     * the immediately preceeding unit (if any).
+     * Unfortunately the clear(int) method results in setting all other units.
      */
     private static void setPrecision(int index, Calendar working) {
-        int i = 0;
-        for(i = 0; i < index; i++) {
-            final int field = CALENDAR_UNITS[i];
-            // Just in case the analysis is wrong, stop clearing if
-            // field value is not the default.
-            final int value = working.get(field);
-            if (value != 0) {
-// DEBUG:                new Throwable("Unexpected value "+value).printStackTrace();
-                break; // stop clearing any further fields
-            }
-            working.clear(field);
+        if (index <= 0) { // e.g. MILLISECONDS
+            return;
+        }
+        final int field = CALENDAR_UNITS[index-1];
+        // Just in case the analysis is wrong, stop clearing if
+        // field value is not the default.
+        final int value = working.get(field);
+        if (value != 0) { // don't reset if it has a value
+//            new Throwable("Unexpected value "+value).printStackTrace(); // DEBUG
+        } else {
+            working.clear(field); // reset just the required field
         }
     }