Skip to content

Commit

Permalink
🐛 fix: Correctly remove suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbiros authored and LupusVirtute committed Sep 23, 2023
1 parent dbc8865 commit afd69de
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main/java/org/lupus/commands/core/utils/TimeUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import java.time.Instant
object TimeUtil {
val numberRegex = "\\d*".toRegex()
val timeRegex = "(\\d*mo)|(\\d*d)|(\\d*h)|(\\d*m)|(\\d*s)".toRegex()

fun stringTimeToInstant(input: String): Instant {
return Instant.now().plusSeconds(stringTimeToSeconds(input))
}

fun stringTimeToSeconds(input: String): Long {
val values = timeRegex.findAll(input)
var seconds = 0L
Expand Down Expand Up @@ -39,9 +41,10 @@ object TimeUtil {
epochSecond -= calcRest*timeClassifier.numberValue
builder.append(output).append(' ')
}
builder.removeSuffix(" ")
builder = builder.removeSuffix(" ")
return builder.toString()
}

private fun classifyAndCheck(classifier: TimeClassifier, input: String): Long {
if (!classifier.classifies(input)) return 0
return classifier.parse(input)
Expand All @@ -53,11 +56,7 @@ object TimeUtil {
TimeClassifier("h\$", 3600L),
TimeClassifier("m\$", 60L),
TimeClassifier("s\$", 1L),


)


)

class TimeClassifier(
val identifier: String,
Expand Down

0 comments on commit afd69de

Please sign in to comment.