MCPcopy Create free account
hub / github.com/MenoData/Time4J / convert

Method convert

base/src/main/java/net/time4j/ClockUnit.java:216–240  ·  view source on GitHub ↗
(
        long sourceDuration,
        ClockUnit sourceUnit
    )

Source from the content-addressed store, hash-verified

214 * @throws ArithmeticException in case of long overflow
215 */
216 public long convert(
217 long sourceDuration,
218 ClockUnit sourceUnit
219 ) {
220
221 if (sourceDuration == 0) {
222 return 0L;
223 }
224
225 int o1 = this.ordinal();
226 int o2 = sourceUnit.ordinal();
227
228 if (o1 == o2) {
229 return sourceDuration;
230 } else if (o1 > o2) {
231 return MathUtils.safeMultiply(
232 sourceDuration,
233 FACTORS[o1] / FACTORS[o2]
234 );
235 } else {
236 long factor = FACTORS[o2] / FACTORS[o1];
237 return (sourceDuration / factor); // possible truncation
238 }
239
240 }
241
242 /**
243 * <p>Converts the given duration to an amount in this unit and performs

Callers 1

normalizeMethod · 0.45

Calls 10

safeMultiplyMethod · 0.95
safeAddMethod · 0.95
safeNegateMethod · 0.95
isEmptyMethod · 0.65
getTotalLengthMethod · 0.65
getMethod · 0.65
isNegativeMethod · 0.65
sizeMethod · 0.45
getUnitMethod · 0.45
getAmountMethod · 0.45

Tested by

no test coverage detected