/** Create a Duration from the number of microseconds. */ public static Duration fromMicros(long microseconds) { return normalizedDuration( microseconds / MICROS_PER_SECOND, (int) (microseconds % MICROS_PER_SECOND * NANOS_PER_MICROSECOND)); }
/** Create a Duration from the number of milliseconds. */ public static Duration fromMillis(long milliseconds) { return normalizedDuration( milliseconds / MILLIS_PER_SECOND, (int) (milliseconds % MILLIS_PER_SECOND * NANOS_PER_MILLISECOND)); }
/** Create a Duration from the number of nanoseconds. */ public static Duration fromNanos(long nanoseconds) { return normalizedDuration( nanoseconds / NANOS_PER_SECOND, (int) (nanoseconds % NANOS_PER_SECOND)); }
/** Create a Duration from the number of seconds. */ public static Duration fromSeconds(long seconds) { return normalizedDuration(seconds, 0); }
return normalizedDuration(seconds, nanos); } catch (IllegalArgumentException e) { throw new ParseException("Duration value is out of range.", 0);
/** Subtract a duration from another. */ public static Duration subtract(Duration d1, Duration d2) { checkValid(d1); checkValid(d2); return normalizedDuration( checkedSubtract(d1.getSeconds(), d2.getSeconds()), checkedSubtract(d1.getNanos(), d2.getNanos())); }
/** Calculate the difference between two timestamps. */ public static Duration between(Timestamp from, Timestamp to) { checkValid(from); checkValid(to); return Durations.normalizedDuration( checkedSubtract(to.getSeconds(), from.getSeconds()), checkedSubtract(to.getNanos(), from.getNanos())); }
/** Add two durations. */ public static Duration add(Duration d1, Duration d2) { checkValid(d1); checkValid(d2); return normalizedDuration( checkedAdd(d1.getSeconds(), d2.getSeconds()), checkedAdd(d1.getNanos(), d2.getNanos())); }