Merge pull request #27149 from marckchr

* pr/27149:
  Polish "Fix duration to microseconds conversion"
  Fix duration to microseconds conversion

Closes gh-27149
This commit is contained in:
Stephane Nicoll
2021-07-06 09:09:57 +02:00
2 changed files with 10 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -183,7 +183,7 @@ public enum DurationStyle {
/**
* Microseconds.
*/
MICROS(ChronoUnit.MICROS, "us", (duration) -> duration.toMillis() * 1000L),
MICROS(ChronoUnit.MICROS, "us", (duration) -> duration.toNanos() / 1000L),
/**
* Milliseconds.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -231,9 +231,15 @@ class DurationStyleTests {
}
@Test
void printSimpleWithUnitShouldPrintInUnit() {
void printSimpleWithSecondsUnitShouldPrintInUnit() {
Duration duration = Duration.ofMillis(1000);
assertThat(DurationStyle.SIMPLE.print(duration, ChronoUnit.SECONDS)).isEqualTo("1s");
}
@Test
void printSimpleWithMicrosUnitShouldPrintInUnit() {
Duration duration = Duration.ofNanos(2000);
assertThat(DurationStyle.SIMPLE.print(duration, ChronoUnit.MICROS)).isEqualTo("2us");
}
}