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
12 changes: 12 additions & 0 deletions src/main/antlr3/org/natty/generated/DateParser.g
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ relative_date
| (THE WHITE_SPACE)? relative_date_span WHITE_SPACE AFTER WHITE_SPACE NEXT
-> ^(RELATIVE_DATE ^(SEEK DIRECTION[">"] SEEK_BY["by_day"] INT["2"] relative_date_span))

// after the weekend -> next monday
// Note: "weekend" is lexed as SATURDAY token (see DateLexer.g); the result is the
// Monday following the upcoming weekend, matching "after the weekend" semantics.
| AFTER WHITE_SPACE THE WHITE_SPACE SATURDAY
-> ^(RELATIVE_DATE ^(SEEK DIRECTION[">"] SEEK_BY["by_day"] INT["1"] ^(DAY_OF_WEEK INT["2"])))

// before the weekend -> next friday
// Note: "weekend" is lexed as SATURDAY token (see DateLexer.g); the result is the
// Friday immediately preceding the upcoming weekend.
| BEFORE WHITE_SPACE THE WHITE_SPACE SATURDAY
-> ^(RELATIVE_DATE ^(SEEK DIRECTION[">"] SEEK_BY["by_day"] INT["1"] ^(DAY_OF_WEEK INT["6"])))

// today, tomorrow
| named_relative_date

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/natty/DateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public void testRelative() throws Exception {
validateDate(reference, "4 mondays from now", 3, 28, 2011);
validateDate(reference, "4 mondays from today", 3, 28, 2011);
validateDate(reference, "next weekend", 3, 12, 2011);
// "after the weekend" returns the Monday following the upcoming weekend (Mar 5-6)
validateDate(reference, "after the weekend", 3, 7, 2011);
validateDate(reference, "After The Weekend", 3, 7, 2011);
// "before the weekend" returns the Friday immediately before the upcoming weekend (Mar 5-6)
validateDate(reference, "before the weekend", 3, 4, 2011);
validateDate(reference, "Before The Weekend", 3, 4, 2011);
validateDate(reference, "six mondays ago", 1, 17, 2011);
validateDate(reference, "last monday", 2, 21, 2011);
validateDate(reference, "last mon", 2, 21, 2011);
Expand Down