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.
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
}
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.
The code changes are shown below. I'll attach a source file as well.