diff --git a/src/main/antlr3/org/natty/generated/DateParser.g b/src/main/antlr3/org/natty/generated/DateParser.g index de8ad2f3..5155ed66 100644 --- a/src/main/antlr3/org/natty/generated/DateParser.g +++ b/src/main/antlr3/org/natty/generated/DateParser.g @@ -461,6 +461,10 @@ explicit_relative_month_seek | THE WHITE_SPACE MONTH WHITE_SPACE AFTER WHITE_SPACE NEXT -> ^(SEEK DIRECTION[">"] SEEK_BY["by_day"] INT["2"] SPAN["month"]) + // the month (current month) + | THE WHITE_SPACE MONTH + -> ^(SEEK DIRECTION[">"] SEEK_BY["by_day"] INT["0"] SPAN["month"]) + // september | relaxed_month -> ^(SEEK DIRECTION[">"] SEEK_BY["by_day"] INT["0"] relaxed_month) @@ -486,6 +490,10 @@ explicit_relative_week_seek // the week after next | THE WHITE_SPACE WEEK WHITE_SPACE AFTER WHITE_SPACE NEXT -> ^(SEEK DIRECTION[">"] SEEK_BY["by_day"] INT["2"] SPAN["week"]) + + // the week (current week) + | THE WHITE_SPACE WEEK + -> ^(SEEK DIRECTION[">"] SEEK_BY["by_day"] INT["0"] SPAN["week"]) ; explicit_relative_fortnight_seek diff --git a/src/test/java/org/natty/AbstractTest.java b/src/test/java/org/natty/AbstractTest.java index 00d26184..931a82c5 100644 --- a/src/test/java/org/natty/AbstractTest.java +++ b/src/test/java/org/natty/AbstractTest.java @@ -50,7 +50,7 @@ protected List parseCollection(Date referenceDate, String value) { */ protected Date parseSingleDate(String value, Date referenceDate) { List dates = parseCollection(referenceDate, value); - Assert.assertEquals(1, dates.size()); + Assert.assertEquals("didn't find a date in '" + value + "' at all", 1, dates.size()); return dates.get(0); } diff --git a/src/test/java/org/natty/DateTest.java b/src/test/java/org/natty/DateTest.java index 05398546..7840cd76 100644 --- a/src/test/java/org/natty/DateTest.java +++ b/src/test/java/org/natty/DateTest.java @@ -175,6 +175,8 @@ public void testRelative() throws Exception { validateDate(reference, "1 year 9 months 1 day from now", 11, 29, 2012); validateDate(reference, "2 years 4 months ago", 10, 28, 2008); validateDate(reference, "2 years 4 months 5 days ago", 10, 23, 2008); + validateDate(reference, "end of the week", 3, 4, 2011); + validateDate(reference, "end of the month", 2, 28, 2011); } @Test diff --git a/src/test/java/org/natty/grammar/DateGrammarTest.java b/src/test/java/org/natty/grammar/DateGrammarTest.java index c97b3466..0fad4a86 100644 --- a/src/test/java/org/natty/grammar/DateGrammarTest.java +++ b/src/test/java/org/natty/grammar/DateGrammarTest.java @@ -389,6 +389,18 @@ public void explicit_relative_date() throws Exception { assertAST("at the end of last month", "(RELATIVE_DATE (SEEK < by_week 1 month) (EXPLICIT_SEEK (DAY_OF_MONTH 31)))"); + assertAST("end of the week", + "(RELATIVE_DATE (SEEK > by_day 0 week) (EXPLICIT_SEEK (DAY_OF_WEEK 6)))"); + + assertAST("end of the month", + "(RELATIVE_DATE (SEEK > by_day 0 month) (EXPLICIT_SEEK (DAY_OF_MONTH 31)))"); + + assertAST("beginning of the week", + "(RELATIVE_DATE (SEEK > by_day 0 week) (EXPLICIT_SEEK (DAY_OF_WEEK 2)))"); + + assertAST("beginning of the month", + "(RELATIVE_DATE (SEEK > by_day 0 month) (EXPLICIT_SEEK (DAY_OF_MONTH 1)))"); + assertAST("the second day of april", "(RELATIVE_DATE (SEEK > by_day 0 (MONTH_OF_YEAR 4)) (EXPLICIT_SEEK (DAY_OF_MONTH 2)))");