From: David ‘Bombe’ Roden Date: Thu, 1 Aug 2019 05:21:29 +0000 (+0200) Subject: 🐛 Fix bug with nanosecond display X-Git-Tag: v81^2~140 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=eb0f48920f5a30217a780f79181540b81c89faba;p=Sone.git 🐛 Fix bug with nanosecond display --- diff --git a/src/main/kotlin/net/pterodactylus/sone/template/DurationFormatFilter.kt b/src/main/kotlin/net/pterodactylus/sone/template/DurationFormatFilter.kt index 559c9da..db49ef1 100644 --- a/src/main/kotlin/net/pterodactylus/sone/template/DurationFormatFilter.kt +++ b/src/main/kotlin/net/pterodactylus/sone/template/DurationFormatFilter.kt @@ -53,7 +53,7 @@ private enum class FixedDuration { override val symbol = "ms" }, MICROS { - override fun number(duration: Duration) = duration.nano / 1_1000.0 + override fun number(duration: Duration) = duration.nano / 1_000.0 override val symbol = "μs" }, NANOS { diff --git a/src/test/kotlin/net/pterodactylus/sone/template/DurationFormatFilterTest.kt b/src/test/kotlin/net/pterodactylus/sone/template/DurationFormatFilterTest.kt index 9e378a8..fa62b50 100644 --- a/src/test/kotlin/net/pterodactylus/sone/template/DurationFormatFilterTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/template/DurationFormatFilterTest.kt @@ -81,6 +81,16 @@ class DurationFormatFilterTest { verifyDuration(123456789, "123.5ms", "ns") } + @Test + fun `123456 with scale ns is rendered as “123_5μs”`() { + verifyDuration(123456, "123.5μs", "ns") + } + + @Test + fun `123 with scale ns is rendered as “123_0ns”`() { + verifyDuration(123, "123.0ns", "ns") + } + private fun verifyDuration(value: Any, expectedRendering: String, scale: String? = null) { assertThat(filter.format(null, value, scale?.let { mapOf("scale" to scale) } ?: emptyMap()), equalTo(expectedRendering)) }