@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()); }
@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 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 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); }
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(); }
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; }