File tree 1 file changed +19
-1
lines changed
fake-kotlinx-time/jvm/src
1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 5
5
6
6
package kotlinx.time
7
7
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 `Instant.now()` 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
+ so the KDoc for [Clock] does not mention any of this. */
15
+ Instant .fromEpochMilliseconds(System .currentTimeMillis())
16
+ }
17
+
18
+ /* *
19
+ * `false` for Android devices with API level < 24, where java.time is not available.
20
+ */
21
+ private val javaTimeAvailable = try {
22
+ java.time.Instant .now()
23
+ true
24
+ } catch (e: NoClassDefFoundError ) {
25
+ false
26
+ }
You can’t perform that action at this time.
0 commit comments