public static Duration multiply(Duration duration, long times) { return createDurationFromBigInteger(toBigInteger(duration).multiply(toBigInteger(times))); }
public static Duration divide(Duration duration, double value) { return multiply(duration, 1.0 / value); }
private static Duration createDurationFromBigInteger(BigInteger value) { long seconds = value.divide(new BigInteger(String.valueOf(NANOS_PER_SECOND))).longValue(); int nanos = value.remainder(new BigInteger(String.valueOf(NANOS_PER_SECOND))).intValue(); return normalizedDuration(seconds, nanos); }
public static long divide(Duration d1, Duration d2) { return toBigInteger(d1).divide(toBigInteger(d2)).longValue(); }
public static Duration multiply(Duration duration, double times) { double result = duration.getSeconds() * times + duration.getNanos() * times / 1000000000.0; if (result < Long.MIN_VALUE || result > Long.MAX_VALUE) { throw new IllegalArgumentException("Result is out of valid range."); } long seconds = (long) result; int nanos = (int) ((result - seconds) * 1000000000); return normalizedDuration(seconds, nanos); }
private static BigInteger toBigInteger(Duration duration) { return toBigInteger(duration.getSeconds()) .multiply(NANOS_PER_SECOND_BIG_INTEGER) .add(toBigInteger(duration.getNanos())); }
public static Duration divide(Duration duration, long times) { return createDurationFromBigInteger(toBigInteger(duration).divide(toBigInteger(times))); }
public static Duration remainder(Duration d1, Duration d2) { return createDurationFromBigInteger(toBigInteger(d1).remainder(toBigInteger(d2))); }