public String formatCompact(Object durationObject) { StringBuffer toAppendTo = new StringBuffer(); long duration = ((Duration) durationObject).getEncodedMillis(); if (((Duration) durationObject).isWork() && Duration.getType(duration) != TimeUnit.NON_TEMPORAL) { duration = Duration.setAsTimeUnit(duration, ScheduleOption.getInstance().getWorkUnit()); } double value = Duration.getValue(duration); int type = Duration.getEffectiveType(duration); if (value > 0D && showPlusSign) toAppendTo.append("+"); boolean isPercent = Duration.isPercent(duration); if (isPercent) value *= 100.0; toAppendTo.append(DECIMAL_FORMAT.format(value)); String unit = formatTypeUnit( type, (Math.abs(value) == 1.0), false, Duration.isPercent(duration), Duration.isEstimated(duration), 3); toAppendTo.append(unit); return toAppendTo.toString(); }
/* (non-Javadoc) * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) */ public StringBuffer format(Object durationObject, StringBuffer toAppendTo, FieldPosition pos) { long duration = ((Duration) durationObject).getEncodedMillis(); if (((Duration) durationObject).isWork() && Duration.getType(duration) != TimeUnit.NON_TEMPORAL) { duration = Duration.setAsTimeUnit(duration, ScheduleOption.getInstance().getWorkUnit()); } double value = Duration.getValue(duration); int type = Duration.getEffectiveType(duration); if (value > 0D && showPlusSign) toAppendTo.append("+"); boolean isPercent = Duration.isPercent(duration); if (isPercent) value *= 100.0; DECIMAL_FORMAT.format(value, toAppendTo, pos); String unit = formatTypeUnit( type, (Math.abs(value) == 1.0), EditOption.getInstance().isAddSpaceBeforeLabel(), Duration.isPercent(duration), Duration.isEstimated(duration), EditOption.getInstance().getViewAs(type)); toAppendTo.append(unit); return toAppendTo; }