Java Code Examples for java.time.Duration#minus()

The following examples show how to use java.time.Duration#minus() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void minus_longTemporalUnit_micros() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, MICROS);
    assertEquals(0, t.getSeconds());
    assertEquals(999999000, t.getNano());
 }
 
Example 2
Source Project: stan.java   File: RedeliveryTests.java    License: Apache License 2.0 5 votes vote down vote up
private void checkTime(String label, Instant time1, Instant time2, Duration expected,
                       Duration tolerance) {
    Duration duration = Duration.between(time1, time2);
    Duration lowerBoundary = expected.minus(tolerance);
    Duration upperBoundary = expected.plus(tolerance);
    if ((duration.compareTo(lowerBoundary) < 0) || (duration.compareTo(upperBoundary) > 0)) {
        fail(String.format("%s not in range: %s (expected %s +/- %s)", label, duration,
                expected, tolerance));
    }
}
 
Example 3
Source Project: hottub   File: TCKDuration.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void minus_longTemporalUnit_millis() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, MILLIS);
    assertEquals(0, t.getSeconds());
    assertEquals(999000000, t.getNano());
 }
 
Example 4
Source Project: j2objc   File: TCKDuration.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void minus_longTemporalUnit_micros() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, MICROS);
    assertEquals(0, t.getSeconds());
    assertEquals(999999000, t.getNano());
 }
 
Example 5
@Test
public void minus_longTemporalUnit_micros() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, MICROS);
    assertEquals(0, t.getSeconds());
    assertEquals(999999000, t.getNano());
 }
 
Example 6
@Test
public void minus_longTemporalUnit_nanos() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, NANOS);
    assertEquals(0, t.getSeconds());
    assertEquals(999999999, t.getNano());
 }
 
Example 7
@Test
public void minus_longTemporalUnit_millis() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, MILLIS);
    assertEquals(0, t.getSeconds());
    assertEquals(999000000, t.getNano());
 }
 
Example 8
@Test
public void minus_longTemporalUnit_micros() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, MICROS);
    assertEquals(0, t.getSeconds());
    assertEquals(999999000, t.getNano());
 }
 
Example 9
Source Project: j2objc   File: TCKDuration.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void minus_longTemporalUnit_nanos() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, NANOS);
    assertEquals(0, t.getSeconds());
    assertEquals(999999999, t.getNano());
 }
 
Example 10
@Test
public void minus_longTemporalUnit_seconds() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, SECONDS);
    assertEquals(0, t.getSeconds());
    assertEquals(0, t.getNano());
 }
 
Example 11
@Test
public void minus_longTemporalUnit_micros() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, MICROS);
    assertEquals(0, t.getSeconds());
    assertEquals(999999000, t.getNano());
 }
 
Example 12
@Test
public void minus_longTemporalUnit_nanos() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, NANOS);
    assertEquals(0, t.getSeconds());
    assertEquals(999999999, t.getNano());
 }
 
Example 13
@Test
public void minus_longTemporalUnit_seconds() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, SECONDS);
    assertEquals(0, t.getSeconds());
    assertEquals(0, t.getNano());
 }
 
Example 14
@Test
public void minus_longTemporalUnit_seconds() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, SECONDS);
    assertEquals(0, t.getSeconds());
    assertEquals(0, t.getNano());
 }
 
Example 15
Source Project: hottub   File: TCKDuration.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test
public void minus_longTemporalUnit_seconds() {
    Duration t = Duration.ofSeconds(1);
    t = t.minus(1, SECONDS);
    assertEquals(0, t.getSeconds());
    assertEquals(0, t.getNano());
 }
 
Example 16
@Test(expectedExceptions=ArithmeticException.class)
public void minusOverflowTooSmall() {
   Duration t = Duration.ofSeconds(Long.MIN_VALUE);
   t.minus(Duration.ofSeconds(0, 1));
}
 
Example 17
@Test(expectedExceptions=ArithmeticException.class)
public void minusOverflowTooSmall() {
   Duration t = Duration.ofSeconds(Long.MIN_VALUE);
   t.minus(Duration.ofSeconds(0, 1));
}
 
Example 18
@Test(expectedExceptions=NullPointerException.class)
public void minus_longTemporalUnit_null() {
   Duration t = Duration.ofSeconds(1);
   t.minus(1, (TemporalUnit) null);
}
 
Example 19
@Test(expectedExceptions=NullPointerException.class)
public void minus_longTemporalUnit_null() {
   Duration t = Duration.ofSeconds(1);
   t.minus(1, (TemporalUnit) null);
}
 
Example 20
Source Project: j2objc   File: TCKDuration.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void minus_longTemporalUnit_null() {
   Duration t = Duration.ofSeconds(1);
   t.minus(1, (TemporalUnit) null);
}