feat: added getTimeUnformated function to TimeUtil
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
ee6b31a868
commit
47f92a0765
1 changed files with 25 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
package net.moonleay.botendo.util
|
||||
|
||||
import java.time.Duration
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
object TimeUtil {
|
||||
|
@ -87,4 +88,28 @@ object TimeUtil {
|
|||
return s
|
||||
}
|
||||
|
||||
//This 100000%ly can be improved, I wrote this at 2am
|
||||
fun getTimeUnformated(timeStr: String): Long {
|
||||
var days: Long = 0
|
||||
var hours: Long = 0
|
||||
var minutes: Long = 0
|
||||
var seconds: Long = 0
|
||||
val timeArr = timeStr.split(" ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
for (s in timeArr) {
|
||||
Logger.out(s)
|
||||
if (s.endsWith("d")) {
|
||||
days = s.split("d".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].toLong()
|
||||
} else if (s.endsWith("h")) {
|
||||
hours = s.split("h".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].toLong()
|
||||
} else if (s.endsWith("m")) {
|
||||
minutes = s.split("m".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].toLong()
|
||||
} else if (s.endsWith("s")) {
|
||||
seconds = s.split("s".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0].toLong()
|
||||
}
|
||||
}
|
||||
val value = Duration.ofSeconds(seconds).plus(Duration.ofMinutes(minutes)).plus(Duration.ofHours(hours))
|
||||
.plus(Duration.ofDays(days)).toMillis()
|
||||
return value
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue