Author: sebb Date: Wed Dec 10 11:19:07 2014 New Revision: 1644375 URL: http://svn.apache.org/r1644375 Log: NET-562 FTPFile.toFormattedString should print only signficant parts of the parsed date Part 1: detect which parts are present TODO: set Calendar to indicate which parts are significant
Modified: commons/proper/net/trunk/src/changes/changes.xml commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPFile.java Modified: commons/proper/net/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1644375&r1=1644374&r2=1644375&view=diff ============================================================================== --- commons/proper/net/trunk/src/changes/changes.xml [utf-8] (original) +++ commons/proper/net/trunk/src/changes/changes.xml [utf-8] Wed Dec 10 11:19:07 2014 @@ -68,6 +68,9 @@ This is mainly a bug-fix release. See fu IMAPExportMbox (example app) allows IMAP folders to be exported into an mbox file. This is the inverse of the IMAPImportMbox example added previously "> + <action issue="NET-562" type="update" dev="sebb"> + FTPFile.toFormattedString should print only signficant parts of the parsed date + </action> <action issue="NET-563" type="fix" dev="sebb"> MLSxEntryParser needs test cases; parsing is too lax </action> Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPFile.java URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPFile.java?rev=1644375&r1=1644374&r2=1644375&view=diff ============================================================================== --- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPFile.java (original) +++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPFile.java Wed Dec 10 11:19:07 2014 @@ -18,7 +18,9 @@ package org.apache.commons.net.ftp; import java.io.Serializable; import java.util.Calendar; +import java.util.Date; import java.util.Formatter; +import java.util.TimeZone; /*** * The FTPFile class is used to represent information about files stored @@ -401,9 +403,21 @@ public class FTPFile implements Serializ fmt.format(" %8d", Long.valueOf(getSize())); Calendar timestamp = getTimestamp(); if (timestamp != null) { - fmt.format(" %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", timestamp); - fmt.format(" %1$tZ", timestamp); - sb.append(' '); + fmt.format(" %1$tY-%1$tm-%1$td", timestamp); + // Only display time units if they are present + if (timestamp.isSet(Calendar.HOUR_OF_DAY)) { + fmt.format(" %1$tH", timestamp); + if (timestamp.isSet(Calendar.MINUTE)) { + fmt.format(":%1$tM", timestamp); + if (timestamp.isSet(Calendar.SECOND)) { + fmt.format(":%1$tS", timestamp); + if (timestamp.isSet(Calendar.MILLISECOND)) { + fmt.format(".%1$tL", timestamp); + } + } + } + fmt.format(" %1$tZ", timestamp); + } } sb.append(' '); sb.append(getName());