Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
handle native Dates
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Newson committed Apr 4, 2009
1 parent 087dcec commit 181988d
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.EvaluatorException;
import org.mozilla.javascript.Function;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
Expand Down Expand Up @@ -155,7 +156,6 @@ public static void jsFunction_date(final Context cx, final Scriptable thisObj, f
}

final String field = args[0].toString();
final String value = args[1].toString();

final Field.Store str;
if (args.length > 2) {
Expand All @@ -164,6 +164,18 @@ public static void jsFunction_date(final Context cx, final Scriptable thisObj, f
} else {
str = Field.Store.NO;
}

// Is it a native date?
try {
final Date date = (Date) Context.jsToJava(args[1], Date.class);
doc.doc.add(new Field(field, Long.toString(date.getTime()), str, Field.Index.NOT_ANALYZED_NO_NORMS));
return;
} catch (final EvaluatorException e) {
// Ignore.
}

// Try to parse it as a string.
final String value= Context.toString(args[1]);

final DateFormat[] formats;
if (args.length > 3) {
Expand Down

0 comments on commit 181988d

Please sign in to comment.