Skip to content

Commit

Permalink
Don't assume relative_time_suffix_anchor is present. Fixes #128
Browse files Browse the repository at this point in the history
  • Loading branch information
joestelmach committed May 13, 2015
1 parent 84ac3a1 commit 57b7fec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/antlr3/com/joestelmach/natty/generated/DateParser.g
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,11 @@ relative_date_suffix
relative_time_suffix
// from now, after today, before noon, after 4pm
: (FROM | AFTER) (WHITE_SPACE relative_time_suffix_anchor)?
-> DIRECTION[">"] SEEK_BY["by_day"] relative_time_suffix_anchor
-> DIRECTION[">"] SEEK_BY["by_day"] relative_time_suffix_anchor?

// before noon, before 3pm
| BEFORE (WHITE_SPACE relative_time_suffix_anchor)?
-> DIRECTION["<"] SEEK_BY["by_day"] relative_time_suffix_anchor
-> DIRECTION["<"] SEEK_BY["by_day"] relative_time_suffix_anchor?

| AGO
-> DIRECTION["<"] SEEK_BY["by_day"]
Expand Down
4 changes: 1 addition & 3 deletions src/test/java/com/joestelmach/natty/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ public void testRelativeDateDifferentTimezone() {

public static void main(String[] args) {

String value="5.30pm";
value = "this friday.";
value = "I want to plan a get-together with my friends for this Friday.";
String value="...all the backstory I needed in the first two minutes. From there, I....";

org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/joestelmach/natty/SearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ public void test() throws Exception {
dates = groups.get(0).getDates();
Assert.assertEquals(1, dates.size());
validateDate(dates.get(0), 11, 21, 2014);

groups = parser.parse("...all the backstory I needed in the first two minutes. From there, I....");
Assert.assertEquals(1, groups.size());
dates = groups.get(0).getDates();
Assert.assertEquals(1, dates.size());
validateDateTime(dates.get(0), 2, 20, 2011, 0, 2, 0);
}

@Test
Expand Down

0 comments on commit 57b7fec

Please sign in to comment.