private String format( String pattern, long amount ) { for (int i = 0, n = pattern.length(); i < n; i++) { if ( (i < n - 2) && (pattern.charAt(i) == '{') && (pattern.charAt(i + 1) == '0') && (pattern.charAt(i + 2) == '}') ) { StringBuilder sb = new StringBuilder(pattern); sb.replace(i, i + 3, this.format(amount)); return sb.toString(); } } if (amount < 0) { return this.minusSign + pattern; } return pattern; }
/** * <p>Formats given duration in clock units. </p> * * @param amount count of units (quantity) * @param unit clock unit * @param width text width (ABBREVIATED as synonym for SHORT) * @return formatted output * @since 1.2 * @see #print(Duration, TextWidth) */ /*[deutsch] * <p>Formatiert die angegebene Dauer in Uhrzeiteinheiten. </p> * * @param amount Anzahl der Einheiten * @param unit Uhrzeiteinheit * @param width text width (ABBREVIATED as synonym for SHORT) * @return formatierte Ausgabe * @since 1.2 * @see #print(Duration, TextWidth) */ public String print( long amount, ClockUnit unit, TextWidth width ) { String pattern = UnitPatterns.of(this.locale).getPattern(width, this.getCategory(amount), unit); return this.format(pattern, amount); }
) { IsoUnit unit = ((i == 7) ? NANOS : STD_UNITS[i]); parts.add(this.format(values[i], unit, negative, width)); count++;
private String printRelativeSeconds( Moment t1, Moment t2, long delta ) { if (t1.getPosixTime() >= START_1972 && t2.getPosixTime() >= START_1972) { delta = SI.SECONDS.between(t1, t2); // leap second correction } if (delta == 0) { return UnitPatterns.of(this.locale).getNowWord(); } long amount = Math.abs(delta); String pattern = ( (delta < 0) ? this.getPastPattern(amount, ClockUnit.SECONDS) : this.getFuturePattern(amount, ClockUnit.SECONDS)); return this.format(pattern, amount); }
return this.format(pattern, amount);
? this.getPastPattern(amount, unit) : this.getFuturePattern(amount, unit)); return this.format(pattern, amount);
return this.format(pattern, amount);