Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
07164382
Commit
07164382
authored
May 09, 2020
by
Karlatemp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update duration display
parent
781af6d8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
2 deletions
+55
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/TimeUtils.kt
.../src/commonMain/kotlin/net.mamoe.mirai/utils/TimeUtils.kt
+22
-1
mirai-core/src/commonTest/kotlin/net/mamoe/mirai/utils/TimeTest.kt
...e/src/commonTest/kotlin/net/mamoe/mirai/utils/TimeTest.kt
+31
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/BotImpl.kt
View file @
07164382
...
...
@@ -24,6 +24,7 @@ import net.mamoe.mirai.network.closeAndJoin
import
net.mamoe.mirai.utils.*
import
net.mamoe.mirai.utils.internal.retryCatching
import
kotlin.coroutines.CoroutineContext
import
kotlin.time.Duration
import
kotlin.time.ExperimentalTime
import
kotlin.time.measureTime
...
...
@@ -138,7 +139,7 @@ abstract class BotImpl<N : BotNetworkHandler> constructor(
reconnect
()
}
logger
.
info
{
"Reconnected successfully in ${time.
inMilliseconds} ms
"
}
logger
.
info
{
"Reconnected successfully in ${time.
asHumanReadable}
"
}
}
is
BotOfflineEvent
.
Active
->
{
val
msg
=
if
(
event
.
cause
==
null
)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/TimeUtils.kt
View file @
07164382
...
...
@@ -15,6 +15,10 @@ package net.mamoe.mirai.utils
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmSynthetic
import
kotlin.math.floor
import
kotlin.time.Duration
import
kotlin.time.DurationUnit
import
kotlin.time.ExperimentalTime
/**
* 时间戳
...
...
@@ -76,4 +80,21 @@ inline val Int.weeksToSeconds: Long
@
get
:
JvmSynthetic
inline
val
Int
.
monthsToSeconds
:
Long
get
()
=
this
*
30
.
daysToSeconds
\ No newline at end of file
get
()
=
this
*
30
.
daysToSeconds
@ExperimentalTime
val
Duration
.
asHumanReadable
:
String
get
()
{
val
builder
=
StringBuilder
()
val
days
=
toInt
(
DurationUnit
.
DAYS
)
val
hours
=
toInt
(
DurationUnit
.
HOURS
)
%
24
val
minutes
=
toInt
(
DurationUnit
.
MINUTES
)
%
60
val
s
=
floor
(
toDouble
(
DurationUnit
.
SECONDS
)
%
60
*
1000
)
/
1000
with
(
builder
)
{
if
(
days
!=
0
)
append
(
"${days}d "
)
if
(
hours
!=
0
)
append
(
"${hours}h "
)
if
(
minutes
!=
0
)
append
(
"${minutes}min "
)
append
(
"${s}s"
)
}
return
builder
.
toString
()
}
mirai-core/src/commonTest/kotlin/net/mamoe/mirai/utils/TimeTest.kt
0 → 100644
View file @
07164382
/*
* Copyright 2020 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/master/LICENSE
*/
package
net.mamoe.mirai.utils
import
kotlin.test.Test
import
kotlin.test.assertTrue
import
kotlin.time.DurationUnit
import
kotlin.time.ExperimentalTime
import
kotlin.time.toDuration
internal
class
TimeTest
{
@ExperimentalTime
@Test
fun
testTimeHumanReadable
()
{
val
time0
=
1
.
toDuration
(
DurationUnit
.
DAYS
)
+
20
.
toDuration
(
DurationUnit
.
HOURS
)
+
15
.
toDuration
(
DurationUnit
.
MINUTES
)
+
2057
.
toDuration
(
DurationUnit
.
MILLISECONDS
)
println
(
time0
.
asHumanReadable
)
assertTrue
{
time0
.
asHumanReadable
==
"1d 20h 15min 2.057s"
}
val
time1
=
1
.
toDuration
(
DurationUnit
.
DAYS
)
+
59
.
toDuration
(
DurationUnit
.
MINUTES
)
println
(
time1
.
asHumanReadable
)
assertTrue
{
time1
.
asHumanReadable
==
"1d 59min 0.0s"
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment