/** * Adds two specified {@link Duration} instances. * @param left The first {@link Duration} to add. * @param right The second {@link Duration} to add. * @return The sum of {@code left} and {@code right}. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'Duration +(Duration,Duration)'") @Nonnull public static Duration add(@Nonnull Duration left, @Nonnull Duration right) { return left.add(right); }
/** * Adds a specified number of seconds to this {@link Duration} and returns the new {@link Duration}. * @param seconds The number of seconds to add. * @return A new {@link Duration} which is the sum of the original {@link Duration} and the specified number of seconds. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final Duration addSeconds(double seconds) { return add(fromSeconds(seconds)); }
/** * Adds a specified number of days to this {@link Duration} and returns the new {@link Duration}. * @param days The number of days to add. * @return A new {@link Duration} which is the sum of the original {@link Duration} and the specified number of days. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final Duration addDays(double days) { return add(fromDays(days)); }
/** * Tests the addition operation between two {@link Duration} instances with unspecified time standards. */ @Test public final void testAddition() { Duration original = new Duration(5, 1000.0); Duration add = Duration.fromSeconds(50.0); Duration result = Duration.add(original, add); Assert.assertEquals((int) 5, (int) result.getDays()); Assert.assertEquals(1050.0, result.getSeconds(), 0d); original = new Duration(5, 8382.1); add = new Duration(1, 10.0); result = Duration.add(original, add); Assert.assertEquals((int) 6, (int) result.getDays()); Assert.assertEquals(8392.1, result.getSeconds(), 0d); original = new Duration(5, 86000.0); add = Duration.fromSeconds(1000.0); result = Duration.add(original, add); Assert.assertEquals((int) 6, (int) result.getDays()); Assert.assertEquals(600.0, result.getSeconds(), 0d); }