Natty is a natural language date parser written in Java. Given a date expression, natty will apply standard language recognition and translation techniques to produce a list of corresponding dates with optional parse and syntax information. Give it a try.

Natty recognizes dates described in many ways, including formal dates (02/28/1979), relaxed dates (oct 1st), relative dates (the day before next thursday), and even date alternatives (next wed or thurs).

Natty is also able to search for date components within a larger block of text, detect their structure, and report line and column information.

Take a look at the documentation for a complete description, and let us know if natty doesn't recognize something it should.

Getting started with natty is easy:

  1. Include the following dependency in your pom.xml file:

    If you're not using Maven, you can download the latest jar file from github.

  2. Use the Parser class to parse your input string into a list of DateGroup's. Each DateGroup contains a list of Date's, the original value and location of the matching text, granular parse and abstract syntax tree information, and simple recurrence information.

    import com.joestelmach.natty.*;
    Parser parser = new Parser();
    List groups = parser.parse("the day before next thursday");
    for(DateGroup group:groups) {
      List dates = group.getDates();
      int line = group.getLine();
      int column = group.getPosition();
      String matchingValue = group.getText();
      String syntaxTree = group.getSyntaxTree().toStringTree();
      Map> parseMap = group.getParseLocations();
      boolean isRecurreing = group.isRecurring();
      Date recursUntil = group.getRecursUntil();

Keep in mind that natty is still quite young, and its API may change as it reaches maturity. If you'd like to leave some feedback, you can submit an issue on github, or contact me directly at joestelmach@gmail.com.