PrettyTimeParser { public List<Date> parse(String language) { language = words2numbers(language); List<Date> result = new ArrayList<Date>(); List<com.joestelmach.natty.DateGroup> groups = parser.parse(language); for (com.joestelmach.natty.DateGroup group : groups) { result.addAll(group.getDates()); } return result; } PrettyTimeParser(TimeZone timezone);  PrettyTimeParser(); List<Date> parse(String language); List<DateGroup> parseSyntax(String language);  }
@Test public void testParseTimes() { List<Date> parse = new PrettyTimeParser().parse("let's get lunch at two pm"); Assert.assertFalse(parse.isEmpty()); Calendar calendar = Calendar.getInstance(); calendar.setTime(parse.get(0)); Assert.assertEquals(14, calendar.get(Calendar.HOUR_OF_DAY)); }
@Test public void testParsePrettyTimeTime() { List<Date> parse = new PrettyTimeParser().parse("I did it three days ago"); Assert.assertFalse(parse.isEmpty()); String formatted = new PrettyTime(Locale.ENGLISH).format(parse.get(0)); Assert.assertEquals("3 days ago", formatted); }
@Test public void testParseYesterday() { Calendar yesterday = Calendar.getInstance(); yesterday.setTime(new Date()); yesterday.add(Calendar.DAY_OF_MONTH, -1); List<Date> parse = new PrettyTimeParser().parse("yesterday"); Assert.assertFalse(parse.isEmpty()); Calendar parsedDate = Calendar.getInstance(); parsedDate.setTime(parse.get(0)); Assert.assertEquals(yesterday.get(Calendar.DAY_OF_MONTH), parsedDate.get(Calendar.DAY_OF_MONTH)); Assert.assertEquals(yesterday.get(Calendar.MONTH), parsedDate.get(Calendar.MONTH)); Assert.assertEquals(yesterday.get(Calendar.YEAR), parsedDate.get(Calendar.YEAR)); }