mirror of
https://github.com/mamoe/mirai.git
synced 2025-04-25 13:03:35 +08:00
Implement TimeUtils
This commit is contained in:
parent
3db5e7bf8c
commit
dd37f9562a
mirai-core-utils/src
commonMain/kotlin
nativeMain/kotlin
nativeTest/kotlin
@ -7,12 +7,10 @@
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
@file:JvmMultifileClass
|
||||
@file:JvmName("MiraiUtils")
|
||||
@file:JvmName("TimeUtilsKt_common")
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
import kotlin.jvm.JvmMultifileClass
|
||||
import kotlin.jvm.JvmName
|
||||
import kotlin.jvm.JvmSynthetic
|
||||
import kotlin.math.floor
|
||||
|
34
mirai-core-utils/src/nativeMain/kotlin/TimeUtils.kt
Normal file
34
mirai-core-utils/src/nativeMain/kotlin/TimeUtils.kt
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
import kotlinx.cinterop.cValue
|
||||
import kotlinx.cinterop.memScoped
|
||||
import kotlinx.cinterop.pointed
|
||||
import platform.posix.CLOCK_REALTIME
|
||||
import platform.posix.clock_gettime
|
||||
import platform.posix.timespec
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*
|
||||
* @see System.currentTimeMillis
|
||||
*/
|
||||
actual fun currentTimeMillis(): Long {
|
||||
memScoped {
|
||||
val s = cValue<timespec>()
|
||||
clock_gettime(CLOCK_REALTIME, s.ptr)
|
||||
return s.ptr.pointed.tv_nsec / 1000
|
||||
}
|
||||
}
|
||||
|
||||
actual fun currentTimeFormatted(format: String?): String {
|
||||
TODO("Not yet implemented")
|
||||
}
|
@ -9,15 +9,13 @@
|
||||
|
||||
package net.mamoe.mirai.utils
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
*
|
||||
* @see System.currentTimeMillis
|
||||
*/
|
||||
actual fun currentTimeMillis(): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
actual fun currentTimeFormatted(format: String?): String {
|
||||
TODO("Not yet implemented")
|
||||
internal class TimeUtilsTest {
|
||||
|
||||
@Test
|
||||
fun `can get currentTimeMillis`() {
|
||||
assertTrue { currentTimeMillis() > 1000 }
|
||||
}
|
||||
}
|
10
mirai-core-utils/src/nativeTest/kotlin/package.kt
Normal file
10
mirai-core-utils/src/nativeTest/kotlin/package.kt
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2019-2022 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
*
|
||||
* https://github.com/mamoe/mirai/blob/dev/LICENSE
|
||||
*/
|
||||
|
||||
package net.mamoe.mirai.utils
|
Loading…
Reference in New Issue
Block a user