blob: d0f5e5d0594619887e2397f89217f3a1f42534f9 [file] [log] [blame]
Roman Elizarovaa461cf2018-04-11 13:20:29 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarovaa461cf2018-04-11 13:20:29 +03003 */
4
5package kotlinx.coroutines.experimental.timeunit
6
7/**
8 * Time unit. This class is provided for better JVM interoperability.
9 * **It is available for common code, but its use in common code is not recommended.**
10 */
11@Deprecated("Using this TimeUnit enum in JS code is not recommended, use functions without it")
12public actual enum class TimeUnit {
13 /** Milliseconds. */
14 MILLISECONDS,
15 /** Seconds. */
16 SECONDS;
17
18 /**
19 * Converts time in this time unit to milliseconds.
20 */
21 public actual fun toMillis(time: Long): Long = when(this) {
22 MILLISECONDS -> time
23 SECONDS -> when {
24 time >= Long.MAX_VALUE / 1000L -> Long.MAX_VALUE
25 time <= Long.MIN_VALUE / 1000L -> Long.MIN_VALUE
26 else -> time * 1000L
27 }
28 }
29}