private static long durationToUnits(Duration duration, TimeUnit units) { // TODO(user): Handle overflow. switch (units) { case NANOSECONDS: return Durations.toNanos(duration); case MICROSECONDS: return Durations.toMicros(duration); default: return units.convert(Durations.toMillis(duration), TimeUnit.MILLISECONDS); } } }
/** * Convert a Duration to the number of microseconds.The result will be * rounded towards 0 to the nearest microseconds. E.g., if the duration * represents -1 nanosecond, it will be rounded to 0. * * @deprecated Use {@link Durations#toMicros} instead. */ @Deprecated public static long toMicros(Duration duration) { return Durations.toMicros(duration); }
private static long durationToUnits(Duration duration, TimeUnit units) { // TODO(user): Handle overflow. switch (units) { case NANOSECONDS: return Durations.toNanos(duration); case MICROSECONDS: return Durations.toMicros(duration); default: return units.convert(Durations.toMillis(duration), TimeUnit.MILLISECONDS); } } }