Java Duration Calculate multiply(Duration duration, double factor)

Here you can find the source of multiply(Duration duration, double factor)

Description

multiply

License

Open Source License

Declaration

public static Duration multiply(Duration duration, double factor) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.time.Duration;

import java.time.temporal.ChronoUnit;

public class Main {
    public static Duration multiply(Duration duration, double factor) {
        final long nanosPerSecond = ChronoUnit.SECONDS.getDuration().toNanos();
        final long nanos = (long) (duration.getNano() * factor);
        return Duration.ofSeconds(
                Math.addExact((long) (duration.getSeconds() * factor), Math.floorDiv(nanos, nanosPerSecond)),
                Math.floorMod(nanos, nanosPerSecond));
    }/*from www . j  av a 2 s .  co  m*/
}

Related

  1. isFinite(Duration duration)
  2. isInfPositive(Duration duration)
  3. max(Duration a, Duration b)
  4. min(Duration a, Duration b)
  5. minutesToDuration(long minutes)
  6. runAfter(Duration duration, Runnable toRun)
  7. seconds(Duration duration)
  8. serializeDuration(Duration duration)
  9. sleep(Duration duration)