Skip to content

Commit

Permalink
Fixing implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nhachicha committed Nov 20, 2023
1 parent d234b75 commit 42a84fa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public expect fun epochInSeconds(): Long

/**
* Returns a RealmInstant representing the time that has passed since the Unix epoch.
* For Android targets < API 26 there's no nano seconds precision.
*/
public expect fun currentTime(): RealmInstant

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package io.realm.kotlin.internal.platform

import io.realm.kotlin.internal.Constants.FILE_COPY_BUFFER_SIZE
import io.realm.kotlin.internal.RealmInstantImpl
import io.realm.kotlin.internal.util.Exceptions
import io.realm.kotlin.types.RealmInstant
import java.io.File
import java.io.InputStream
import java.io.OutputStream
import java.security.DigestInputStream
import java.security.MessageDigest
import java.time.Clock.systemUTC
import java.util.concurrent.TimeUnit
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KType
Expand All @@ -24,15 +21,6 @@ public actual fun threadId(): ULong {
public actual fun epochInSeconds(): Long =
TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())

/**
* Since internalNow() should only logically return a value after the Unix epoch, it is safe to create a RealmInstant
* without considering having to pass negative nanoseconds.
*/
public actual fun currentTime(): RealmInstant {
val jtInstant = systemUTC().instant()
return RealmInstantImpl(jtInstant.epochSecond, jtInstant.nano)
}

public actual fun fileExists(path: String): Boolean =
File(path).let { it.exists() && it.isFile }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package io.realm.kotlin.internal.platform

import io.realm.kotlin.Realm
import io.realm.kotlin.internal.RealmInstantImpl
import io.realm.kotlin.internal.interop.SyncConnectionParams
import io.realm.kotlin.internal.util.Exceptions
import io.realm.kotlin.log.LogLevel
import io.realm.kotlin.log.RealmLogger
import io.realm.kotlin.types.RealmInstant
import java.io.InputStream
import java.net.URL
import java.time.Clock

public actual val RUNTIME: SyncConnectionParams.Runtime = SyncConnectionParams.Runtime.JVM
public actual val RUNTIME_VERSION: String = System.getProperty("java.version")
Expand All @@ -27,3 +30,13 @@ public actual fun assetFileAsStream(assetFilename: String): InputStream {

public actual fun createDefaultSystemLogger(tag: String, logLevel: LogLevel): RealmLogger =
StdOutLogger(tag, logLevel)

/**
* Since internalNow() should only logically return a value after the Unix epoch, it is safe to create a RealmInstant
* without considering having to pass negative nanoseconds.
*/
@Suppress("NewApi") // The implementation in SystemUtilsAndroid has a guard to only use systemUTC on API >= 26
public actual fun currentTime(): RealmInstant {
val jtInstant = Clock.systemUTC().instant()
return RealmInstantImpl(jtInstant.epochSecond, jtInstant.nano)
}

0 comments on commit 42a84fa

Please sign in to comment.