HTTPCLIENT-1227: Date parsing in DateUtils made more efficient
Contributed by Patrick Linskey <pcl at apache.org> git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1378935 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e29551b32d
commit
90b8646309
|
@ -1,8 +1,12 @@
|
|||
Changes since 4.2.1
|
||||
-------------------
|
||||
|
||||
* [HTTPCLIENT-1227] Date parsing in DateUtils made more efficient.
|
||||
Contributed by Patrick Linskey <pcl at apache.org>
|
||||
|
||||
* [HTTPCLIENT-1223] Cache could be more aggressive on cache invalidations
|
||||
from Content-Location. Contributed by Jon Moore <jonm at apache.org>.
|
||||
Contributed by Jon Moore <jonm at apache.org>
|
||||
|
||||
* [HTTPCLIENT-1216] Added method to force clean thread-local used by DateUtils.
|
||||
Contributed by Oleg Kalnichevski <olegk at apache.org>
|
||||
|
|
|
@ -29,7 +29,7 @@ package org.apache.http.impl.cookie;
|
|||
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
@ -68,8 +68,8 @@ public final class DateUtils {
|
|||
public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
|
||||
|
||||
private static final String[] DEFAULT_PATTERNS = new String[] {
|
||||
PATTERN_RFC1036,
|
||||
PATTERN_RFC1123,
|
||||
PATTERN_RFC1036,
|
||||
PATTERN_ASCTIME
|
||||
};
|
||||
|
||||
|
@ -156,12 +156,10 @@ public final class DateUtils {
|
|||
for (String dateFormat : dateFormats) {
|
||||
SimpleDateFormat dateParser = DateFormatHolder.formatFor(dateFormat);
|
||||
dateParser.set2DigitYearStart(startDate);
|
||||
|
||||
try {
|
||||
return dateParser.parse(dateValue);
|
||||
} catch (ParseException pe) {
|
||||
// ignore this exception, we will try the next format
|
||||
}
|
||||
ParsePosition pos = new ParsePosition(0);
|
||||
Date result = dateParser.parse(dateValue, pos);
|
||||
if (pos.getIndex() != 0)
|
||||
return result;
|
||||
}
|
||||
|
||||
// we were unable to parse the date
|
||||
|
|
Loading…
Reference in New Issue