Permalink
Browse files

correct new Date(str) example and add matching test.

  • Loading branch information...
1 parent e093735 commit 7f4e703cb02a309221981943da912803be2ef24e Robert Newson committed Aug 13, 2010
Showing with 14 additions and 1 deletion.
  1. +1 −1 README.md
  2. +13 −0 src/test/java/com/github/rnewson/couchdb/lucene/DocumentConverterTest.java
View
@@ -208,7 +208,7 @@ doc.add("value");
doc.add(35, {"type":"int"});
// Add a date field.
-doc.add(new Date("2009-01-01"), {"type":"date"});
+doc.add(new Date("January 6, 1972 16:05:00"), {"type":"date"});
// Add a date field (object must be a Date object
@@ -229,6 +229,19 @@ public void testDateObject() throws Exception {
assertThat((Long)((NumericField)result[0].getFieldable("num")).getNumericValue(), is(1284332400000L));
}
+ @Test
+ public void testDateObject2() throws Exception {
+ final String fun = "function(doc) { var ret=new Document(); ret.add(new Date(\"January 6, 1972 16:05:00\"), {type:\"date\", field:\"num\"}); return ret; }";
+ final DocumentConverter converter = new DocumentConverter(context, view(fun));
+ final Document[] result = converter.convert(
+ doc("{_id:\"hi\"}"),
+ settings(),
+ null);
+ assertThat(result.length, is(1));
+ assertThat(result[0].getFieldable("num"), is(NumericField.class));
+ assertThat((Long)((NumericField)result[0].getFieldable("num")).getNumericValue(), is(63561900000L));
+ }
+
@Test
public void testParseInt() throws Exception {
final String fun = "function(doc) { var ret=new Document(); ret.add(parseInt(\"12.5\"), {type:\"int\", field:\"num\"}); return ret; }";

0 comments on commit 7f4e703

Please sign in to comment.