Author: sebb
Date: Wed Dec 10 15:05:05 2014
New Revision: 1644447
URL: http://svn.apache.org/r1644447
Log:
NET-562 FTPFile.toFormattedString should print only signficant parts of the
parsed date
+set Calendar to indicate which parts are significant in Enterprise Parser
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParser.java
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java
Modified:
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParser.java?rev=1644447&r1=1644446&r2=1644447&view=diff
==============================================================================
---
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParser.java
(original)
+++
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParser.java
Wed Dec 10 15:05:05 2014
@@ -120,19 +120,23 @@ public class EnterpriseUnixFTPEntryParse
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.HOUR_OF_DAY, 0);
+
+ int pos = MONTHS.indexOf(mo);
+ int month = pos / 4;
+ final int missingUnit; // the first missing unit
try
{
- int pos = MONTHS.indexOf(mo);
- int month = pos / 4;
if (yr != null)
{
// it's a year; there are no hours and minutes
cal.set(Calendar.YEAR, Integer.parseInt(yr));
+ missingUnit = Calendar.HOUR_OF_DAY;
}
else
{
// it must be hour/minute or we wouldn't have matched
+ missingUnit = Calendar.SECOND;
int year = cal.get(Calendar.YEAR);
// if the month we're reading is greater than now, it must
@@ -147,6 +151,7 @@ public class EnterpriseUnixFTPEntryParse
}
cal.set(Calendar.MONTH, month);
cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(da));
+ cal.clear(missingUnit);
file.setTimestamp(cal);
}
catch (NumberFormatException e)
Modified:
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java?rev=1644447&r1=1644446&r2=1644447&view=diff
==============================================================================
---
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java
(original)
+++
commons/proper/net/trunk/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java
Wed Dec 10 15:05:05 2014
@@ -120,6 +120,20 @@ public class EnterpriseUnixFTPEntryParse
checkPermisions(file);
}
+ public void testPrecisionMinutes() {
+ FTPFile file = getParser().parseFTPEntry("-C--E-----FTP B QUA1I1
18128 5000000000 Aug 12 13:56 QUADTEST");
+ Calendar stamp = file.getTimestamp();
+ assertTrue("Expected minute to be set", stamp.isSet(Calendar.MINUTE));
+ assertFalse("Expected second to be unset",
stamp.isSet(Calendar.SECOND));
+ }
+
+ public void testPrecisionDays() {
+ FTPFile file = getParser().parseFTPEntry("-C--E-----FTP B QUA1I1
18128 5000000000 Aug 12 2014 QUADTEST");
+ Calendar stamp = file.getTimestamp();
+ assertTrue("Expected day to be set",
stamp.isSet(Calendar.DAY_OF_MONTH));
+ assertFalse("Expected hour to be unset",
stamp.isSet(Calendar.HOUR_OF_DAY));
+ }
+
/**
* @see
org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing()
*/