From f119dc80dc5322c922562ae41bc28c07ced1195d Mon Sep 17 00:00:00 2001 From: Stav Raviv Date: Wed, 30 Oct 2024 15:07:32 -0700 Subject: [PATCH 1/2] Fix incorrect currentTime() for Android devices on API 25 and blow Also add millisecond precision --- .../io/realm/kotlin/internal/platform/SystemUtilsAndroid.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/library-base/src/androidMain/kotlin/io/realm/kotlin/internal/platform/SystemUtilsAndroid.kt b/packages/library-base/src/androidMain/kotlin/io/realm/kotlin/internal/platform/SystemUtilsAndroid.kt index 45291eeabd..6369044241 100644 --- a/packages/library-base/src/androidMain/kotlin/io/realm/kotlin/internal/platform/SystemUtilsAndroid.kt +++ b/packages/library-base/src/androidMain/kotlin/io/realm/kotlin/internal/platform/SystemUtilsAndroid.kt @@ -44,6 +44,7 @@ public actual fun currentTime(): RealmInstant { val jtInstant = java.time.Clock.systemUTC().instant() RealmInstantImpl(jtInstant.epochSecond, jtInstant.nano) } else { - RealmInstantImpl(System.currentTimeMillis(), 0) + val now = System.currentTimeMillis() + RealmInstantImpl(now / 1000, (now % 1000).toInt() * 1_000_000) } } From dbea3a31fe24e65492bcf60ee7d430b7d2372d44 Mon Sep 17 00:00:00 2001 From: Stav Raviv Date: Fri, 1 Nov 2024 11:24:35 -0700 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19f4386c27..a0bad6a088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ * None. ### Fixed -* None. +* `RealmInstant.now` was returning incorrect value on Android devices running API 25 and below (Issue: [#1849](https://github.com/realm/realm-kotlin/issues/1849)). ### Compatibility * File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later).