StringToTime extends Date { public static Object time(Object dateTimeString) { return time(dateTimeString, new Date()); } StringToTime();  StringToTime(Date date);  StringToTime(Object dateTimeString);  StringToTime(Object dateTimeString, String simpleDateFormat);  StringToTime(Object dateTimeString, Date now);  StringToTime(Object dateTimeString, Long now);  StringToTime(Object dateTimeString, Integer now);  StringToTime(Object dateTimeString, Date now, String simpleDateFormat); @Override long getTime(); Calendar getCal(); String format(String simpleDateFormat); @Override String toString(); static Object time(Object dateTimeString); static Object time(Object dateTimeString, Date now); static Object date(Object dateTimeString); static Object date(Object dateTimeString, Date now); static Object cal(Object dateTimeString); static Object cal(Object dateTimeString, Date now);  }
@Test public void testTonight() { Date now = new Date(); assertEquals(StringToTime.time("20:00:00.000", now), StringToTime.time("tonight", now)); }
@Test public void testIncrements() { Date now = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(now); cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) + 1); assertEquals(cal.getTimeInMillis(), StringToTime.time("+1 hour", now)); cal.setTime(now); cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR) + 52); assertEquals(cal.getTimeInMillis(), StringToTime.time("+52 weeks", now)); assertEquals(new StringToTime("1 year", now), new StringToTime("+1 year", now)); assertEquals(new StringToTime("+1 year", now), new StringToTime("+12 months", now)); assertEquals(new StringToTime("+1 year 6 months", now), new StringToTime("+18 months", now)); assertEquals(new StringToTime("12 months 1 day 60 seconds", now), new StringToTime("1 year 24 hours 1 minute", now)); }