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 13:05:04 UTC
svn commit: r1644380 - in /commons/proper/net/trunk/src: changes/changes.xml
main/java/org/apache/commons/net/ftp/FTPFile.java
Author: sebb
Date: Wed Dec 10 12:05:03 2014
New Revision: 1644380
URL: http://svn.apache.org/r1644380
Log:
NET-564 FTPFile.toFormattedString - allow specification of TimeZone for display
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=1644380&r1=1644379&r2=1644380&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 12:05:03 2014
@@ -68,6 +68,8 @@ 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-564" type="update" dev="sebb">
+ FTPFile.toFormattedString - allow specification of TimeZone for display
<action issue="NET-562" type="update" dev="sebb">
FTPFile.toFormattedString should print only signficant parts of the parsed date
</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=1644380&r1=1644379&r2=1644380&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 12:05:03 2014
@@ -386,12 +386,30 @@ public class FTPFile implements Serializ
/***
* Returns a string representation of the FTPFile information.
* This currently mimics the Unix listing format.
+ * This method uses the timezone of the Calendar entry, which is
+ * the server time zone (if one was provided) otherwise it is
+ * the local time zone.
*
* @return A string representation of the FTPFile information.
* @since 3.0
*/
public String toFormattedString()
{
+ return toFormattedString(null);
+ }
+
+ /**
+ * Returns a string representation of the FTPFile information.
+ * This currently mimics the Unix listing format.
+ * This method allows the Calendar time zone to be overridden.
+ *
+ * @param timezone the timezone to use for displaying the time stamp
+ * If {@code null}, then use the Calendar entry timezone
+ * @return A string representation of the FTPFile information.
+ * @since 3.4
+ */
+ public String toFormattedString(final String timezone)
+ {
StringBuilder sb = new StringBuilder();
Formatter fmt = new Formatter(sb);
sb.append(formatType());
@@ -403,6 +421,15 @@ public class FTPFile implements Serializ
fmt.format(" %8d", Long.valueOf(getSize()));
Calendar timestamp = getTimestamp();
if (timestamp != null) {
+ if (timezone != null) {
+ TimeZone newZone = TimeZone.getTimeZone(timezone);
+ if (!newZone.equals(timestamp.getTimeZone())){
+ Date original = timestamp.getTime();
+ Calendar newStamp = Calendar.getInstance(newZone);
+ newStamp.setTime(original);
+ timestamp = newStamp;
+ }
+ }
fmt.format(" %1$tY-%1$tm-%1$td", timestamp);
// Only display time units if they are present
if (timestamp.isSet(Calendar.HOUR_OF_DAY)) {