Adam S
07/12/2023, 10:46 AMMichael Paus
07/12/2023, 10:53 AMAdam S
07/12/2023, 10:53 AMAdam S
07/12/2023, 11:07 AMprivate fun systemTimeMillis(): Long {
return memScoped {
val timespec = alloc<platform.posix.timespec>().ptr
platform.posix.clock_gettime(platform.posix.CLOCK_REALTIME.convert(), timespec)
@OptIn(UnsafeNumber::class)
timespec.pointed
.run { tv_sec.seconds + tv_nsec.nanoseconds }
.inWholeMilliseconds
}
}Adam S
07/12/2023, 11:07 AMprivate fun systemTimeSeconds(): Long {
return memScoped {
val time = alloc<LongVar>()
platform.posix.time(time.ptr)
time.value
}
}ribesg
07/12/2023, 2:56 PMOleg Yukhnevich
07/12/2023, 3:19 PMDuration between to points in time.
What is needed here is to get sorted identifier - time in millis from some point in time which will work between runs of multiple instances of application, not inside one application
So, there is no direct simple replacement in stdlib for this 🙂 only in kotlinx.datetime, or via platform capabilities (code which mentioned above)ephemient
07/12/2023, 4:13 PMgettimeofday is older and available on more platforms than clock_gettime but I don't think it matters for kotlin's targets)Adam S
07/12/2023, 4:14 PMgettimeofday in some StackOverflow answers, but Kotlin doesn’t include it by default - I got Unresolved reference: gettimeofdayephemient
07/12/2023, 4:18 PM