Skip to content

Commit dc8b3db

Browse files
author
Bytekeeper
committed
Added since X timeunit
1 parent 38f08e3 commit dc8b3db

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/antlr/EnglishCommands.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ agoFormat returns [DateTime result]
4747
@init {
4848
$result = DateTime.now();
4949
}
50-
: amount=NUMBER (
50+
: SINCE? amount=NUMBER (
5151
HOURS {$result = $result.minusHours($amount.int); }
5252
| MINUTES {$result = $result.minusMinutes($amount.int); }
5353
| SECONDS {$result = $result.minusSeconds($amount.int); }
54-
) AGO;
54+
) AGO?;
5555

5656
date: NUMBER (DOT|MINUS) NUMBER (DOT|MINUS) NUMBER;
5757

src/test/java/org/stt/g4/EnglishCommandsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ public void shouldParseHrsAgoCommand() {
4141
System.out.println(command.newItem);
4242
}
4343

44+
@Test
45+
public void shouldParseSinceHrsAgoCommand() {
46+
String commandToParse = "test 1 since 2 hrs ago";
47+
CharStream input = new ANTLRInputStream(commandToParse);
48+
EnglishCommandsLexer lexer = new EnglishCommandsLexer(input);
49+
EnglishCommandsParser parser = new EnglishCommandsParser(
50+
new CommonTokenStream(lexer));
51+
CommandContext command = parser.command();
52+
System.out.println(command.newItem);
53+
}
54+
4455
@Test
4556
public void shouldParseSinceCommand() {
4657
String commandToParse = "test 1 since 10:00:00";

0 commit comments

Comments
 (0)