private static <U extends IsoUnit> Item<U> replaceFraction( long amount, U unit ) { if (unit.equals(MILLIS)) { amount = MathUtils.safeMultiply(amount, MIO); unit = cast(NANOS); } else if (unit.equals(MICROS)) { amount = MathUtils.safeMultiply(amount, 1000L); unit = cast(NANOS); } else { return null; } return Item.of(amount, unit); }
private static <U extends IsoUnit> Duration<U> convert( TimeSpan<U> timespan ) { if (timespan instanceof Duration) { return cast(timespan); } else { Duration<U> zero = ofZero(); return zero.plus(timespan); } }
private static <U extends ChronoUnit> ChronoUnit addParsedItem( ChronoUnit unit, ChronoUnit last, // optional long amount, String period, int index, List<Item<U>> items ) throws ParseException { if ( (last == null) || (Double.compare(unit.getLength(), last.getLength()) < 0) ) { if (amount != 0) { U reified = cast(unit); items.add(Item.of(amount, reified)); } return unit; } else if (Double.compare(unit.getLength(), last.getLength()) == 0) { throw new ParseException( "Duplicate unit items: " + period, index); } else { throw new ParseException( "Wrong order of unit items: " + period, index); } }
U unit = cast(YEARS); items.add(Item.of(years, unit)); U unit = cast(MONTHS); items.add(Item.of(months, unit)); U unit = cast(DAYS); items.add(Item.of(days, unit)); from); U unit = cast(HOURS); items.add(Item.of(hours, unit)); from + 2 + (extended ? 1 : 0)); U unit = cast(MINUTES); items.add(Item.of(minutes, unit)); from + 4 + (extended ? 2 : 0)); U unit = cast(SECONDS); items.add(Item.of(seconds, unit)); U unit = cast(NANOS); items.add(Item.of(nanos, unit));
U key = cast(NANOS); temp.add(Item.of(nanos, key)); } else if (temp.isEmpty()) {
return duration; } else if (timespan instanceof Duration) { return cast(timespan);