diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationStyle.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationStyle.java index 36fd244ecf..70992bc17e 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationStyle.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/DurationStyle.java @@ -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. diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/DurationStyleTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/DurationStyleTests.java index 0e160b2a83..9dc23b1c14 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/DurationStyleTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/convert/DurationStyleTests.java @@ -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"); + } + }