Skip to content

Commit a406a46

Browse files
marckchrsnicoll
authored andcommitted
Fix duration to microseconds conversion
See gh-27149
1 parent 877f618 commit a406a46

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationStyle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ enum Unit {
183183
/**
184184
* Microseconds.
185185
*/
186-
MICROS(ChronoUnit.MICROS, "us", (duration) -> duration.toMillis() * 1000L),
186+
MICROS(ChronoUnit.MICROS, "us", duration -> duration.toNanos() / 1000L),
187187

188188
/**
189189
* Milliseconds.

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/DurationStyleTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ void printSimpleWithoutUnitShouldPrintInMs() {
234234
void printSimpleWithUnitShouldPrintInUnit() {
235235
Duration duration = Duration.ofMillis(1000);
236236
assertThat(DurationStyle.SIMPLE.print(duration, ChronoUnit.SECONDS)).isEqualTo("1s");
237+
assertThat(DurationStyle.SIMPLE.print(Duration.ofNanos(2000), ChronoUnit.MICROS)).isEqualTo("2us");
237238
}
238239

239240
}

0 commit comments

Comments
 (0)