Java Code Examples for java.time.Duration#plus()
The following examples show how to use
java.time.Duration#plus() .
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
Source Project: LuckPerms File: DurationParser.java License: MIT License | 6 votes |
public static Duration parseDuration(String input) throws IllegalArgumentException { Matcher matcher = PATTERN.matcher(input); while (matcher.find()) { if (matcher.group() == null || matcher.group().isEmpty()) { continue; } Duration duration = Duration.ZERO; for (int i = 0; i < UNITS.length; i++) { ChronoUnit unit = UNITS[i]; int g = i + 1; if (matcher.group(g) != null && !matcher.group(g).isEmpty()) { int n = Integer.parseInt(matcher.group(g)); if (n > 0) { duration = duration.plus(unit.getDuration().multipliedBy(n)); } } } return duration; } throw new IllegalArgumentException("unable to parse duration: " + input); }
Example 2
Source Project: openjdk-8-source File: TCKDuration.java License: GNU General Public License v2.0 | 5 votes |
@Test public void plus_longTemporalUnit_millis() { Duration t = Duration.ofSeconds(1); t = t.plus(1, MILLIS); assertEquals(1, t.getSeconds()); assertEquals(1000000, t.getNano()); }
Example 3
Source Project: hottub File: TCKDuration.java License: GNU General Public License v2.0 | 5 votes |
@Test public void plus_longTemporalUnit_seconds() { Duration t = Duration.ofSeconds(1); t = t.plus(1, SECONDS); assertEquals(2, t.getSeconds()); assertEquals(0, t.getNano()); }
Example 4
Source Project: j2objc File: TCKDuration.java License: Apache License 2.0 | 5 votes |
@Test public void plus_longTemporalUnit_micros() { Duration t = Duration.ofSeconds(1); t = t.plus(1, MICROS); assertEquals(1, t.getSeconds()); assertEquals(1000, t.getNano()); }
Example 5
Source Project: openjdk-8 File: TCKDuration.java License: GNU General Public License v2.0 | 5 votes |
@Test public void plus_longTemporalUnit_seconds() { Duration t = Duration.ofSeconds(1); t = t.plus(1, SECONDS); assertEquals(2, t.getSeconds()); assertEquals(0, t.getNano()); }
Example 6
Source Project: jdk8u-jdk File: TCKDuration.java License: GNU General Public License v2.0 | 5 votes |
@Test public void plus_longTemporalUnit_nanos() { Duration t = Duration.ofSeconds(1); t = t.plus(1, NANOS); assertEquals(1, t.getSeconds()); assertEquals(1, t.getNano()); }
Example 7
Source Project: jdk8u-jdk File: TCKDuration.java License: GNU General Public License v2.0 | 5 votes |
@Test public void plus_longTemporalUnit_millis() { Duration t = Duration.ofSeconds(1); t = t.plus(1, MILLIS); assertEquals(1, t.getSeconds()); assertEquals(1000000, t.getNano()); }
Example 8
Source Project: jdk8u-jdk File: TCKDuration.java License: GNU General Public License v2.0 | 5 votes |
@Test public void plus_longTemporalUnit_nanos() { Duration t = Duration.ofSeconds(1); t = t.plus(1, NANOS); assertEquals(1, t.getSeconds()); assertEquals(1, t.getNano()); }
Example 9
Source Project: openjdk-8 File: TCKDuration.java License: GNU General Public License v2.0 | 5 votes |
@Test public void plus_longTemporalUnit_millis() { Duration t = Duration.ofSeconds(1); t = t.plus(1, MILLIS); assertEquals(1, t.getSeconds()); assertEquals(1000000, t.getNano()); }
Example 10
Source Project: jdk8u60 File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=ArithmeticException.class) public void plusOverflowTooSmall() { Duration t = Duration.ofSeconds(Long.MIN_VALUE); t.plus(Duration.ofSeconds(-1, 999999999)); }
Example 11
Source Project: dragonwell8_jdk File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=ArithmeticException.class) public void plusOverflowTooSmall() { Duration t = Duration.ofSeconds(Long.MIN_VALUE); t.plus(Duration.ofSeconds(-1, 999999999)); }
Example 12
Source Project: openjdk-jdk8u-backup File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=ArithmeticException.class) public void plusOverflowTooBig() { Duration t = Duration.ofSeconds(Long.MAX_VALUE, 999999999); t.plus(Duration.ofSeconds(0, 1)); }
Example 13
Source Project: jdk8u-dev-jdk File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=ArithmeticException.class) public void plusOverflowTooBig() { Duration t = Duration.ofSeconds(Long.MAX_VALUE, 999999999); t.plus(Duration.ofSeconds(0, 1)); }
Example 14
Source Project: openjdk-jdk8u File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void plus_longTemporalUnit_null() { Duration t = Duration.ofSeconds(1); t.plus(1, (TemporalUnit) null); }
Example 15
Source Project: openjdk-8 File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void plus_longTemporalUnit_null() { Duration t = Duration.ofSeconds(1); t.plus(1, (TemporalUnit) null); }
Example 16
Source Project: jdk8u-dev-jdk File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=ArithmeticException.class) public void plusOverflowTooSmall() { Duration t = Duration.ofSeconds(Long.MIN_VALUE); t.plus(Duration.ofSeconds(-1, 999999999)); }
Example 17
Source Project: j2objc File: TCKDuration.java License: Apache License 2.0 | 4 votes |
@Test(expected=NullPointerException.class) public void plus_longTemporalUnit_null() { Duration t = Duration.ofSeconds(1); t.plus(1, (TemporalUnit) null); }
Example 18
Source Project: TencentKona-8 File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=ArithmeticException.class) public void plusOverflowTooBig() { Duration t = Duration.ofSeconds(Long.MAX_VALUE, 999999999); t.plus(Duration.ofSeconds(0, 1)); }
Example 19
Source Project: jdk8u60 File: TCKDuration.java License: GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=NullPointerException.class) public void plus_longTemporalUnit_null() { Duration t = Duration.ofSeconds(1); t.plus(1, (TemporalUnit) null); }
Example 20
Source Project: j2objc File: TCKDuration.java License: Apache License 2.0 | 4 votes |
@Test(expected=ArithmeticException.class) public void plusOverflowTooSmall() { Duration t = Duration.ofSeconds(Long.MIN_VALUE); t.plus(Duration.ofSeconds(-1, 999999999)); }