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

Method addTo

base/src/main/java/net/time4j/Moment.java:2616–2644  ·  view source on GitHub ↗
(
            Moment context,
            long amount
        )

Source from the content-addressed store, hash-verified

2614 //~ Methoden ------------------------------------------------------
2615
2616 @Override
2617 public Moment addTo(
2618 Moment context,
2619 long amount
2620 ) {
2621
2622 if (this.unit.compareTo(TimeUnit.SECONDS) >= 0) {
2623 long secs =
2624 Math.multiplyExact(amount, this.unit.toSeconds(1));
2625 return Moment.of(
2626 Math.addExact(context.getPosixTime(), secs),
2627 context.getNanosecond(),
2628 POSIX
2629 );
2630 } else { // MILLIS, MICROS, NANOS
2631 long nanos =
2632 Math.multiplyExact(amount, this.unit.toNanos(1));
2633 long sum = Math.addExact(context.getNanosecond(), nanos);
2634 int nano = (int) Math.floorMod(sum, MRD);
2635 long second = Math.floorDiv(sum, MRD);
2636
2637 return Moment.of(
2638 Math.addExact(context.getPosixTime(), second),
2639 nano,
2640 POSIX
2641 );
2642 }
2643
2644 }
2645
2646 @Override
2647 public long between(

Callers

nothing calls this directly

Calls 7

ofMethod · 0.95
toNanosMethod · 0.80
floorModMethod · 0.80
floorDivMethod · 0.80
getPosixTimeMethod · 0.65
getNanosecondMethod · 0.65
compareToMethod · 0.45

Tested by

no test coverage detected