File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
fake-kotlinx-time/jvm/src Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 55
66package kotlinx.time
77
8- internal actual fun currentTime (): Instant = java.time.Instant .now().toKotlinInstant()
8+ internal actual fun currentTime (): Instant = if (javaTimeAvailable) {
9+ java.time.Instant .now().toKotlinInstant()
10+ } else {
11+ /* After experimenting in Android Studio, it seems like on Android with API < 24, only millisecond precision
12+ is available in `java.time.Instant` with core library desugaring enabled. Because of that, `currentTimeMillis`
13+ is good enough + suggesting that our users enable core library desugaring isn't going to bring any benefits. */
14+ Instant .fromEpochMilliseconds(System .currentTimeMillis())
15+ }
16+
17+ /* *
18+ * `false` for Android devices with API level < 24, where java.time is not available.
19+ */
20+ private val javaTimeAvailable = try {
21+ java.time.Instant .now()
22+ true
23+ } catch (e: NoClassDefFoundError ) {
24+ false
25+ }
You can’t perform that action at this time.
0 commit comments