Issue Details (XML | Word | Printable)

Key: NET-191
Type: Bug Bug
Status: Closed Closed
Resolution: Duplicate
Priority: Minor Minor
Assignee: Unassigned
Reporter: Anjan Bacchu
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Net

date parsing in the FTP client doesn't work for 29th Feb (leap years)

Created: 29/Feb/08 10:11 PM   Updated: 01/Mar/08 03:17 PM
Return to search
Component/s: None
Affects Version/s: 1.4
Fix Version/s: None

Time Tracking:
Original Estimate: 24h
Original Estimate - 24h
Remaining Estimate: 24h
Remaining Estimate - 24h
Time Spent: Not Specified
Remaining Estimate - 24h

File Attachments:
  Size
Java Source File Licensed for inclusion in ASF works FTPTimestampParserImpl.java 2008-03-01 02:02 AM John Schneider 8 kB
Environment: solaris/windows 1.4.1 commons-client, java 5
Issue Links:
Duplicate
 

Resolution Date: 01/Mar/08 12:18 PM


 Description  « Hide
http://blogs.lodgon.com/johan/Leap_year_issues_in_apache_commonsnet

We have a production app that is being impacted as well. we have the same issue as the user here : not able to parse LEAP YEAR(29th feb) dates in Ftp client.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
John Schneider added a comment - 01/Mar/08 02:02 AM - edited
I ran into the same issue today. It was a major issue for my organization. I've modified FTPTimestampParserImpl with a workaround that does fix the issue. I invite the community to scrutinize and improve the fix.

The code changes are shown below. I'll attach a source file as well.

public Calendar parseTimestamp(String timestampStr) throws ParseException {
	Calendar now = Calendar.getInstance();
	now.setTimeZone(this.getServerTimeZone());
		
	Calendar working = Calendar.getInstance();
	working.setTimeZone(this.getServerTimeZone());
	ParsePosition pp = new ParsePosition(0);

	Date parsed = null;
	if (this.recentDateFormat != null) {
		parsed = recentDateFormat.parse(timestampStr, pp);
			
		// Start change
		if (parsed == null
				&& new GregorianCalendar().isLeapYear(now
						.get(Calendar.YEAR))) {
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy "
					+ DEFAULT_RECENT_SDF);
			pp = new ParsePosition(0);
			timestampStr = now.get(Calendar.YEAR) + " " + timestampStr;
			parsed = dateFormat.parse(timestampStr, pp);
		}
		// End change
	}

Rory Winston added a comment - 01/Mar/08 12:17 PM
This is a duplicate of NET-188, but thanks for the code suggestion. I it may be a good idea to use the isLeapYear() check you have suggested here.

Rory Winston added a comment - 01/Mar/08 12:18 PM
Dupe of NET-188