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/10 14:54:12 UTC

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

Author: sebb
Date: Wed Dec 10 13:54:11 2014
New Revision: 1644411

URL: http://svn.apache.org/r1644411
Log:
NET-562 FTPFile.toFormattedString should print only signficant parts of the parsed date
+set Calendar to indicate which parts are significant in MLSxEntryParser

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

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java?rev=1644411&r1=1644410&r2=1644411&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java Wed Dec 10 13:54:11 2014
@@ -184,17 +184,24 @@ public class MLSxEntryParser extends FTP
      * @since 3.4
      */
     public static Calendar parseGMTdateTime(String timestamp) {
-        SimpleDateFormat sdf;
+        final SimpleDateFormat sdf;
+        final boolean hasMillis;
         if (timestamp.contains(".")){
             sdf = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
+            hasMillis = true;
         } else {
             sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+            hasMillis = false;
         }
-        TimeZone GMT = TimeZone.getTimeZone("GMT"); // both need to be set for the parse to work OK
+        TimeZone GMT = TimeZone.getTimeZone("GMT");
+        // both timezones need to be set for the parse to work OK
         sdf.setTimeZone(GMT);
         GregorianCalendar gc = new GregorianCalendar(GMT);
         try {
             gc.setTime(sdf.parse(timestamp));
+            if (!hasMillis) {
+                gc.clear(Calendar.MILLISECOND); // flag up missing ms units
+            }
             return gc;
         } catch (ParseException e) {
             return null;