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

The following examples show how to use java.time.Duration#minus() . 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
Source File: RedeliveryTests.java    From stan.java with 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 2
Source File: TCKDuration.java    From hottub with 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 3
Source File: TCKDuration.java    From jdk8u_jdk with 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 4
Source File: TCKDuration.java    From openjdk-8-source with 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 5
Source File: TCKDuration.java    From openjdk-8-source with GNU General Public License v2.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 6
Source File: TCKDuration.java    From TencentKona-8 with GNU General Public License v2.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 7
Source File: TCKDuration.java    From TencentKona-8 with 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 8
Source File: TCKDuration.java    From j2objc with 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 9
Source File: TCKDuration.java    From openjdk-jdk8u-backup with GNU General Public License v2.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 10
Source File: TCKDuration.java    From jdk8u-jdk with 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 11
Source File: TCKDuration.java    From dragonwell8_jdk with GNU General Public License v2.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 12
Source File: TCKDuration.java    From jdk8u-jdk with GNU General Public License v2.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 13
Source File: TCKDuration.java    From j2objc with 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 14
Source File: TCKDuration.java    From hottub with 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 15
Source File: TCKDuration.java    From jdk8u_jdk with GNU General Public License v2.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 16
Source File: TCKDuration.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void minus_longTemporalUnit_null() {
   Duration t = Duration.ofSeconds(1);
   t.minus(1, (TemporalUnit) null);
}
 
Example 17
Source File: TCKDuration.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void minusOverflowTooSmall() {
   Duration t = Duration.ofSeconds(Long.MIN_VALUE);
   t.minus(Duration.ofSeconds(0, 1));
}
 
Example 18
Source File: TCKDuration.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void minus_longTemporalUnit_null() {
   Duration t = Duration.ofSeconds(1);
   t.minus(1, (TemporalUnit) null);
}
 
Example 19
Source File: TCKDuration.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void minusOverflowTooSmall() {
   Duration t = Duration.ofSeconds(Long.MIN_VALUE);
   t.minus(Duration.ofSeconds(0, 1));
}
 
Example 20
Source File: TCKDuration.java    From j2objc with 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);
}