Change Duration.absoluteValue to property
This commit is contained in:
@@ -56,7 +56,7 @@ public inline class Duration internal constructor(internal val _value: Double) :
|
|||||||
fun isInfinite(): Boolean = _value.isInfinite()
|
fun isInfinite(): Boolean = _value.isInfinite()
|
||||||
fun isFinite(): Boolean = _value.isFinite()
|
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)
|
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()) {
|
if (isInfinite()) {
|
||||||
append(_value)
|
append(_value)
|
||||||
} else {
|
} else {
|
||||||
val absNs = absoluteValue().inNanoseconds
|
val absNs = absoluteValue.inNanoseconds
|
||||||
var scientific = false
|
var scientific = false
|
||||||
var maxDecimals = 0
|
var maxDecimals = 0
|
||||||
val unit = when {
|
val unit = when {
|
||||||
@@ -153,7 +153,7 @@ public inline class Duration internal constructor(internal val _value: Double) :
|
|||||||
fun toIsoString(): String = buildString {
|
fun toIsoString(): String = buildString {
|
||||||
if (isNegative()) append('-')
|
if (isNegative()) append('-')
|
||||||
append('P')
|
append('P')
|
||||||
absoluteValue().toComponents { days, hours, minutes, seconds, nanoseconds ->
|
absoluteValue.toComponents { days, hours, minutes, seconds, nanoseconds ->
|
||||||
if (days != 0)
|
if (days != 0)
|
||||||
append(days).append('D')
|
append(days).append('D')
|
||||||
|
|
||||||
|
|||||||
@@ -207,9 +207,9 @@ class DurationTest {
|
|||||||
assertFalse(zero.isNegative())
|
assertFalse(zero.isNegative())
|
||||||
assertFalse(positive.isNegative())
|
assertFalse(positive.isNegative())
|
||||||
|
|
||||||
assertEquals(positive, negative.absoluteValue())
|
assertEquals(positive, negative.absoluteValue)
|
||||||
assertEquals(positive, positive.absoluteValue())
|
assertEquals(positive, positive.absoluteValue)
|
||||||
assertEquals(zero, zero.absoluteValue())
|
assertEquals(zero, zero.absoluteValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user