1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 13:03:35 +08:00

Implement TimeUtils

This commit is contained in:
Him188 2022-05-26 17:25:24 +01:00
parent 3db5e7bf8c
commit dd37f9562a
No known key found for this signature in database
GPG Key ID: BA439CDDCF652375
4 changed files with 53 additions and 13 deletions
mirai-core-utils/src
commonMain/kotlin
nativeMain/kotlin
nativeTest/kotlin

View File

@ -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

View 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")
}

View File

@ -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 }
}
}

View 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