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 2008/04/07 02:27:05 UTC

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

Author: sebb
Date: Sun Apr  6 17:27:04 2008
New Revision: 645336

URL: http://svn.apache.org/viewvc?rev=645336&view=rev
Log:
NET-188 - apply patch of 12/Mar/08 01:19 PM; fixes Feb 29 parsing

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

Modified: commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java?rev=645336&r1=645335&r2=645336&view=diff
==============================================================================
--- commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java (original)
+++ commons/proper/net/trunk/src/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java Sun Apr  6 17:27:04 2008
@@ -97,10 +97,22 @@
 		ParsePosition pp = new ParsePosition(0);
 
 		Date parsed = null;
+		String timeStampStrPlusYear="";
 		if (recentDateFormat != null) {
-			parsed = recentDateFormat.parse(timestampStr, pp);
+            // Temporarily add the current year to the short date time
+            // to cope with short-date leap year strings.
+            // e.g. Java's DateFormatter will assume that "Feb 29 12:00" refers to 
+            // Feb 29 1970 (an invalid date) rather than a potentially valid leap year date.
+            // This is pretty bad hack to work around the deficiencies of the JDK date/time classes.
+            int year = now.get(Calendar.YEAR);
+            timeStampStrPlusYear = timestampStr + " " + year;
+            SimpleDateFormat hackFormatter = new SimpleDateFormat(recentDateFormat.toPattern() + " yyyy", 
+                    recentDateFormat.getDateFormatSymbols());
+            hackFormatter.setLenient(false);
+            hackFormatter.setTimeZone(recentDateFormat.getTimeZone());
+            parsed = hackFormatter.parse(timeStampStrPlusYear, pp);
 		}
-		if (parsed != null && pp.getIndex() == timestampStr.length()) 
+		if (parsed != null && pp.getIndex() == timeStampStrPlusYear.length()) 
 		{
 			working.setTime(parsed);
 			working.set(Calendar.YEAR, now.get(Calendar.YEAR));
@@ -114,41 +126,21 @@
 				working.add(Calendar.YEAR, -1);
 			}
 		} else {
-			// Temporarily add the current year to the short date time
-			// to cope with short-date leap year strings.
-			// e.g. Java's DateFormatter will assume that "Feb 29 12:00" refers to 
-			// Feb 29 1970 (an invalid date) rather than a potentially valid leap year date.
-			// This is pretty bad hack to work around the deficiencies of the JDK date/time classes.
-			if (recentDateFormat != null) {
-				pp = new ParsePosition(0);
-				int year = now.get(Calendar.YEAR);
-				String timeStampStrPlusYear = timestampStr + " " + year;
-				SimpleDateFormat hackFormatter = new SimpleDateFormat(recentDateFormat.toPattern() + " yyyy", 
-						recentDateFormat.getDateFormatSymbols());
-				hackFormatter.setLenient(false);
-				hackFormatter.setTimeZone(recentDateFormat.getTimeZone());
-				parsed = hackFormatter.parse(timeStampStrPlusYear, pp);
-			}
-			if (parsed != null && pp.getIndex() == timestampStr.length() + 5) {
+			pp = new ParsePosition(0);
+			parsed = defaultDateFormat.parse(timestampStr, pp);
+			// note, length checks are mandatory for us since
+			// SimpleDateFormat methods will succeed if less than
+			// full string is matched.  They will also accept, 
+			// despite "leniency" setting, a two-digit number as
+			// a valid year (e.g. 22:04 will parse as 22 A.D.) 
+			// so could mistakenly confuse an hour with a year, 
+			// if we don't insist on full length parsing.
+			if (parsed != null && pp.getIndex() == timestampStr.length()) {
 				working.setTime(parsed);
-			}
-			else {
-				pp = new ParsePosition(0);
-				parsed = defaultDateFormat.parse(timestampStr, pp);
-				// note, length checks are mandatory for us since
-				// SimpleDateFormat methods will succeed if less than
-				// full string is matched.  They will also accept, 
-				// despite "leniency" setting, a two-digit number as
-				// a valid year (e.g. 22:04 will parse as 22 A.D.) 
-				// so could mistakenly confuse an hour with a year, 
-				// if we don't insist on full length parsing.
-				if (parsed != null && pp.getIndex() == timestampStr.length()) {
-					working.setTime(parsed);
-				} else {
-					throw new ParseException(
-							"Timestamp could not be parsed with older or recent DateFormat", 
-							pp.getIndex());
-				}
+			} else {
+				throw new ParseException(
+						"Timestamp could not be parsed with older or recent DateFormat", 
+						pp.getIndex());
 			}
 		}
 		return working;