Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-65, Handles more modification-date format

Jerome Charrond087bc5ae0cc
diff --git a/lib/commons-lang-2.1.jar b/lib/commons-lang-2.1.jar
new file mode 100644
index 000000000..87b80ab5d
Binary files /dev/null and b/lib/commons-lang-2.1.jar differ
diff --git a/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java b/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
index 0cf49436b..61994528b 100644
--- a/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
+++ b/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
@@ -53,7 +53,7 @@ import java.util.TimeZone;
import java.util.Enumeration;
import java.util.Properties;
-
+import org.apache.commons.lang.time.DateUtils;
/**
* Add (or reset) a few metaData properties as respective fields
* (if they are available), so that they can be displayed by more.jsp
@@ -133,21 +133,37 @@ public class MoreIndexingFilter implements IndexingFilter {
try {
time = HttpDateFormat.toLong(date);
} catch (ParseException e) {
- // try to parse it as date in alternative format
- String date2 = date;
- try {
- if (date.length() > 25 ) date2 = date.substring(0, 25);
- DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss", Locale.US);
- time = df.parse(date2).getTime();
- } catch (Exception e1) {
- try {
- if (date.length() > 24 ) date2 = date.substring(0, 24);
- DateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US);
- time = df.parse(date2).getTime();
- } catch (Exception e2) {
- LOG.warning(url + ": can't parse erroneous date: " + date);
- }
- }
+ // try to parse it as date in alternative format
+ try {
+ Date parsedDate = DateUtils.parseDate(date,
+ new String [] {
+ "EEE MMM dd HH:mm:ss yyyy",
+ "EEE MMM dd HH:mm:ss yyyy zzz",
+ "EEE, MMM dd HH:mm:ss yyyy zzz",
+ "EEE, dd MMM yyyy HH:mm:ss zzz",
+ "EEE,dd MMM yyyy HH:mm:ss zzz",
+ "EEE, dd MMM yyyy HH:mm:sszzz",
+ "EEE, dd MMM yyyy HH:mm:ss",
+ "EEE, dd-MMM-yy HH:mm:ss zzz",
+ "yyyy/MM/dd HH:mm:ss.SSS zzz",
+ "yyyy/MM/dd HH:mm:ss.SSS",
+ "yyyy/MM/dd HH:mm:ss zzz",
+ "yyyy/MM/dd",
+ "yyyy.MM.dd HH:mm:ss",
+ "yyyy-MM-dd HH:mm",
+ "MMM dd yyyy HH:mm:ss. zzz",
+ "MMM dd yyyy HH:mm:ss zzz",
+ "dd.MM.yyyy HH:mm:ss zzz",
+ "dd MM yyyy HH:mm:ss zzz",
+ "dd.MM.yyyy; HH:mm:ss",
+ "dd.MM.yyyy HH:mm:ss",
+ "dd.MM.yyyy zzz"
+ });
+ time = parsedDate.getTime();
+ // LOG.warning(url + ": parsed date: " + date +" to:"+time);
+ } catch (Exception e2) {
+ LOG.warning(url + ": can't parse erroneous date: " + date);
+ }
}
return time;
}