PrettyTimeParser { public List<DateGroup> parseSyntax(String language) { language = words2numbers(language); List<DateGroup> result = new ArrayList<DateGroup>(); List<com.joestelmach.natty.DateGroup> groups = parser.parse(language); Date now = new Date(); for (com.joestelmach.natty.DateGroup group : groups) { result.add(new DateGroupImpl(now, group)); } return result; } PrettyTimeParser(TimeZone timezone);  PrettyTimeParser(); List<Date> parse(String language); List<DateGroup> parseSyntax(String language);  }
@Test @Ignore public void testParseAmbiguousTimes() { List<DateGroup> parse = new PrettyTimeParser().parseSyntax("let's get lunch at two"); Assert.assertFalse(parse.isEmpty()); Calendar calendar = Calendar.getInstance(); calendar.setTime(parse.get(0).getDates().get(0)); int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); if (hourOfDay >= 2 && hourOfDay < 14) Assert.assertEquals(14, calendar.get(Calendar.HOUR_OF_DAY)); else Assert.assertEquals(2, calendar.get(Calendar.HOUR_OF_DAY)); }
@Test public void testParseSyntax() { List<DateGroup> parse = new PrettyTimeParser().parseSyntax("I did it three days ago"); Assert.assertFalse(parse.isEmpty()); String formatted = new PrettyTime(Locale.ENGLISH).format(parse.get(0).getDates().get(0)); Assert.assertEquals("3 days ago", formatted); Assert.assertEquals(1, parse.get(0).getLine()); Assert.assertEquals(9, parse.get(0).getPosition()); Assert.assertEquals(1, parse.get(0).getDates().size()); Assert.assertNull(parse.get(0).getRecursUntil()); Assert.assertFalse(parse.get(0).isRecurring()); Assert.assertEquals(-1, parse.get(0).getRecurInterval()); }
@Test @Ignore public void testParseSyntaxRecurring() { List<DateGroup> parse = new PrettyTimeParser().parseSyntax("I do it every three days"); Assert.assertFalse(parse.isEmpty()); String formatted = new PrettyTime(Locale.ENGLISH).format(parse.get(0).getDates().get(0)); Assert.assertEquals("3 days from now", formatted); Assert.assertEquals(1, parse.get(0).getLine()); Assert.assertEquals(14, parse.get(0).getPosition()); Assert.assertEquals(1, parse.get(0).getDates().size()); Assert.assertNull(parse.get(0).getRecursUntil()); Assert.assertTrue(parse.get(0).isRecurring()); Assert.assertEquals(1000 * 60 * 60 * 24 * 3l, parse.get(0).getRecurInterval()); }