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

The following examples show how to use java.time.Duration#getUnits() . 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: spring-vault   File: DurationParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Format a {@link Duration} into the Go format representation.
 * @param duration the duration object to format.
 * @return the duration formatted in Go's duration format.
 */
public static String formatDuration(Duration duration) {

	StringBuilder builder = new StringBuilder();

	for (TemporalUnit unit : duration.getUnits()) {

		if (unit == ChronoUnit.MINUTES) {
			builder.append(duration.get(unit)).append('m');
		}
		if (unit == ChronoUnit.HOURS) {
			builder.append(duration.get(unit)).append('h');
		}
		if (unit == ChronoUnit.SECONDS) {
			builder.append(duration.get(unit)).append('s');
		}
		if (unit == ChronoUnit.MILLIS) {
			builder.append(duration.get(unit)).append("ms");
		}
		if (unit == ChronoUnit.NANOS) {
			builder.append(duration.get(unit)).append("ns");
		}
	}

	return builder.toString();
}
 
Example 2
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 3
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 4
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 5
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 6
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 7
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 8
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 9
Source Project: hottub   File: TCKDuration.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 10
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 11
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 12
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 13
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 14
@Test(groups="{tck}")
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals(units.size(), 2, "Period.getUnits length");
    assertTrue(units.contains(ChronoUnit.SECONDS), "Period.getUnits contains ChronoUnit.SECONDS");
    assertTrue(units.contains(ChronoUnit.NANOS), "contains ChronoUnit.NANOS");
}
 
Example 15
Source Project: j2objc   File: TCKDuration.java    License: Apache License 2.0 5 votes vote down vote up
@Test()
public void test_duration_getUnits() {
    Duration duration = Duration.ofSeconds(5000, 1000);
    List<TemporalUnit> units = duration.getUnits();
    assertEquals("Period.getUnits length", units.size(), 2);
    assertTrue("Period.getUnits contains ChronoUnit.SECONDS", units.contains(ChronoUnit.SECONDS));
    assertTrue("contains ChronoUnit.NANOS", units.contains(ChronoUnit.NANOS));
}