Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/antlr3/org/natty/generated/DateParser.g
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/natty/AbstractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected List<Date> parseCollection(Date referenceDate, String value) {
*/
protected Date parseSingleDate(String value, Date referenceDate) {
List<Date> 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);
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/natty/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/org/natty/grammar/DateGrammarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)))");

Expand Down