diff --git a/src/main/antlr3/org/natty/generated/DateParser.g b/src/main/antlr3/org/natty/generated/DateParser.g index de8ad2f..a1f9d53 100644 --- a/src/main/antlr3/org/natty/generated/DateParser.g +++ b/src/main/antlr3/org/natty/generated/DateParser.g @@ -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 diff --git a/src/test/java/org/natty/DateTest.java b/src/test/java/org/natty/DateTest.java index 0539854..1855a12 100644 --- a/src/test/java/org/natty/DateTest.java +++ b/src/test/java/org/natty/DateTest.java @@ -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);