Change Duration.absoluteValue to property

This commit is contained in:
Ilya Gorbunov
2019-05-30 20:52:55 +03:00
parent 3f7a0d0845
commit 365cbb94cd
2 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -56,7 +56,7 @@ public inline class Duration internal constructor(internal val _value: Double) :
fun isInfinite(): Boolean = _value.isInfinite()
fun isFinite(): Boolean = _value.isFinite()
fun absoluteValue(): Duration = if (isNegative()) -this else this
val absoluteValue: Duration get() = if (isNegative()) -this else this
override fun compareTo(other: Duration): Int = this._value.compareTo(other._value)
@@ -111,7 +111,7 @@ public inline class Duration internal constructor(internal val _value: Double) :
if (isInfinite()) {
append(_value)
} else {
val absNs = absoluteValue().inNanoseconds
val absNs = absoluteValue.inNanoseconds
var scientific = false
var maxDecimals = 0
val unit = when {
@@ -153,7 +153,7 @@ public inline class Duration internal constructor(internal val _value: Double) :
fun toIsoString(): String = buildString {
if (isNegative()) append('-')
append('P')
absoluteValue().toComponents { days, hours, minutes, seconds, nanoseconds ->
absoluteValue.toComponents { days, hours, minutes, seconds, nanoseconds ->
if (days != 0)
append(days).append('D')
+3 -3
View File
@@ -207,9 +207,9 @@ class DurationTest {
assertFalse(zero.isNegative())
assertFalse(positive.isNegative())
assertEquals(positive, negative.absoluteValue())
assertEquals(positive, positive.absoluteValue())
assertEquals(zero, zero.absoluteValue())
assertEquals(positive, negative.absoluteValue)
assertEquals(positive, positive.absoluteValue)
assertEquals(zero, zero.absoluteValue)
}