### Question:
IntervalDatum extends Datum { @Override public String asChars() { try { StringBuilder sb = new StringBuilder(); String prefix = ""; if (months != 0) { int positiveNum = Math.abs(months); int year = positiveNum / 12; int remainMonth = positiveNum - year * 12; if (year > 0) { sb.append(months < 0 ? "-" : ""); sb.append(year).append(year == 1 ? " year" : " years"); prefix = " "; } sb.append(prefix).append(months < 0 ? "-" : "").append(remainMonth).append(months == 1 ? " month" : " months"); prefix = " "; } formatMillis(sb, prefix, milliseconds); return sb.toString(); } catch (Exception e) { return ""; } } IntervalDatum(long milliseconds);  IntervalDatum(int months, long milliseconds);  IntervalDatum(String intervalStr); static long parseTime(String timeStr); int getMonths(); long getMilliSeconds(); @Override Datum plus(Datum datum); @Override Datum minus(Datum datum); @Override Datum multiply(Datum datum); @Override Datum divide(Datum datum); @Override long asInt8(); @Override String toString(); @Override String asChars(); static String formatMillis(long millis); static void formatMillis(StringBuilder sb, String prefix, long millis); @Override int size(); @Override int compareTo(Datum datum); @Override Datum equalsTo(Datum datum); @Override boolean equals(Object obj); @Override int hashCode(); static final long MINUTE_MILLIS; static final long HOUR_MILLIS; static final long DAY_MILLIS; static final long MONTH_MILLIS; }### Answer:
@Test public final void parseIntervalDatum() { IntervalDatum datum = new IntervalDatum("3y 5month 10day 23:50:40.200"); assertEquals("3 years 5 months 10 days 23:50:40.200", datum.asChars()); datum = new IntervalDatum("23:50:40.200 5month 10day 3y"); assertEquals("3 years 5 months 10 days 23:50:40.200", datum.asChars()); datum = new IntervalDatum("3y 5month 10 day 23:50:40.200"); assertEquals("3 years 5 months 10 days 23:50:40.200", datum.asChars()); datum = new IntervalDatum("3years 5months 10 day 23:50:40.200"); assertEquals("3 years 5 months 10 days 23:50:40.200", datum.asChars()); datum = new IntervalDatum("5 hour"); assertEquals("05:00:00", datum.asChars()); try { datum = new IntervalDatum("3years 5months 10 day 1h 23:50:40.200"); fail("hour and time format can not be used at the same time in interval."); } catch (InvalidOperationException e) { } }
@Test public final void testAsText() { IntervalDatum datum = new IntervalDatum(14, IntervalDatum.DAY_MILLIS + 10 * IntervalDatum.HOUR_MILLIS + 20 * IntervalDatum.MINUTE_MILLIS + 30 * 1000 + 400); assertEquals("1 year 2 months 1 day 10:20:30.400", datum.asChars()); }