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

Commit

Permalink
correct new Date(str) example and add matching test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Newson committed Aug 13, 2010
1 parent e093735 commit 7f4e703
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }";
Expand Down

0 comments on commit 7f4e703

Please sign in to comment.