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

Method plus

base/src/main/java/net/time4j/Moment.java:1367–1433  ·  view source on GitHub ↗
(
        long amount,
        SI unit
    )

Source from the content-addressed store, hash-verified

1365 * @throws ArithmeticException in case of overflow
1366 */
1367 public Moment plus(
1368 long amount,
1369 SI unit
1370 ) {
1371
1372 Moment.check1972(this);
1373
1374 if (amount == 0) {
1375 return this;
1376 }
1377
1378 Moment result;
1379
1380 try {
1381 switch (unit) {
1382 case SECONDS:
1383 if (LeapSeconds.getInstance().isEnabled()) {
1384 result = new Moment(
1385 Math.addExact(this.getElapsedTimeUTC(), amount),
1386 this.getNanosecond(),
1387 UTC);
1388 } else {
1389 result = Moment.of(
1390 Math.addExact(this.posixTime, amount),
1391 this.getNanosecond(),
1392 POSIX
1393 );
1394 }
1395 break;
1396 case NANOSECONDS:
1397 long sum =
1398 Math.addExact(this.getNanosecond(), amount);
1399 int nano = (int) Math.floorMod(sum, MRD);
1400 long second = Math.floorDiv(sum, MRD);
1401
1402 if (LeapSeconds.getInstance().isEnabled()) {
1403 result = new Moment(
1404 Math.addExact(this.getElapsedTimeUTC(), second),
1405 nano,
1406 UTC
1407 );
1408 } else {
1409 result = Moment.of(
1410 Math.addExact(this.posixTime, second),
1411 nano,
1412 POSIX
1413 );
1414 }
1415 break;
1416 default:
1417 throw new UnsupportedOperationException();
1418 }
1419 } catch (IllegalArgumentException iae) {
1420 ArithmeticException ex =
1421 new ArithmeticException(
1422 "Result beyond boundaries of time axis.");
1423 ex.initCause(iae);
1424 throw ex;

Callers 15

clockFromTime4JMethod · 0.95
plusMachineTimeUTCMethod · 0.95
plusMachineTimePOSIXMethod · 0.95
nowMomentMethod · 0.95
offsetOneMinuteMethod · 0.95
smartMomentMethod · 0.95
minusMethod · 0.95
applyMethod · 0.95
createFromMethod · 0.95
withValueMethod · 0.95

Calls 10

check1972Method · 0.95
getInstanceMethod · 0.95
getElapsedTimeUTCMethod · 0.95
getNanosecondMethod · 0.95
ofMethod · 0.95
floorModMethod · 0.80
floorDivMethod · 0.80
isEnabledMethod · 0.45
getSecondsMethod · 0.45
getFractionMethod · 0.45

Tested by 10

clockFromTime4JMethod · 0.76
plusMachineTimeUTCMethod · 0.76
plusMachineTimePOSIXMethod · 0.76
nowMomentMethod · 0.76
offsetOneMinuteMethod · 0.76
smartMomentMethod · 0.76
sqlTimestampToTime4JMethod · 0.36