Make DurationUnit not a typealias of TimeUnit on JVM

Provide conversion functions between DurationUnit and TimeUnit
This commit is contained in:
Ilya Gorbunov
2021-09-28 02:02:29 +03:00
committed by Space
parent 2b1897e362
commit 04d70162d2
5 changed files with 119 additions and 18 deletions
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package test.time
import java.util.concurrent.TimeUnit
import kotlin.test.*
import kotlin.time.*
@OptIn(ExperimentalTime::class)
class DurationUnitJVMTest {
@Test
fun conversionFromTimeUnit() {
for (unit in DurationUnit.values()) {
val timeUnit = unit.toTimeUnit()
assertEquals(unit.name, timeUnit.name)
assertEquals(unit, timeUnit.toDurationUnit())
}
for (timeUnit in TimeUnit.values()) {
val unit = timeUnit.toDurationUnit()
assertEquals(timeUnit.name, unit.name)
assertEquals(timeUnit, unit.toTimeUnit())
}
}
}