Skip to content

Commit 9cdc455

Browse files
authored
[RKOTLIN-1137] Fix incorrect currentTime() for Android devices on API 25 and below (#1850)
1 parent df49eef commit 9cdc455

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* None.
88

99
### Fixed
10-
* None.
10+
* `RealmInstant.now` was returning incorrect value on Android devices running API 25 and below (Issue: [#1849](https://github.com/realm/realm-kotlin/issues/1849)).
1111

1212
### Compatibility
1313
* File format: Generates Realms with file format v24 (reads and upgrades file format v10 or later).

packages/library-base/src/androidMain/kotlin/io/realm/kotlin/internal/platform/SystemUtilsAndroid.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public actual fun currentTime(): RealmInstant {
4444
val jtInstant = java.time.Clock.systemUTC().instant()
4545
RealmInstantImpl(jtInstant.epochSecond, jtInstant.nano)
4646
} else {
47-
RealmInstantImpl(System.currentTimeMillis(), 0)
47+
val now = System.currentTimeMillis()
48+
RealmInstantImpl(now / 1000, (now % 1000).toInt() * 1_000_000)
4849
}
4950
}

0 commit comments

Comments
 (0)