AgeTag extends TagSupport { protected static String getAsAgeString(final Date start, final Date stop) { if (start == null || stop == null) { return ""; } final String s = DurationFormatUtils.formatDurationWords(stop.getTime() - start.getTime(), true, true); final Matcher m = PATTERN.matcher(s); m.matches(); return m.group(1); }  @Override int doStartTag(); void setDate(final Date date);  }
@Test public void testGetAsAgeString() throws Exception { final Calendar start = new GregorianCalendar(2007, 0, 1, 0, 0, 0); final Calendar stop = (Calendar) start.clone(); stop.add(Calendar.SECOND, 25); assertEquals("25 seconds", AgeTag.getAsAgeString(start.getTime(), stop.getTime())); stop.add(Calendar.MINUTE, 31); assertEquals("31 minutes", AgeTag.getAsAgeString(start.getTime(), stop.getTime())); stop.add(Calendar.HOUR, 25); assertEquals("1 day", AgeTag.getAsAgeString(start.getTime(), stop.getTime())); stop.add(Calendar.MONTH, 8); assertEquals("244 days", AgeTag.getAsAgeString(start.getTime(), stop.getTime())); stop.add(Calendar.WEEK_OF_YEAR, 6); assertEquals("286 days", AgeTag.getAsAgeString(start.getTime(), stop.getTime())); stop.add(Calendar.YEAR, 1); assertEquals("652 days", AgeTag.getAsAgeString(start.getTime(), stop.getTime())); stop.add(Calendar.SECOND, 10); assertEquals("652 days", AgeTag.getAsAgeString(start.getTime(), stop.getTime())); assertEquals("", AgeTag.getAsAgeString(null, null)); }