diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-16 19:47:46 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-16 19:47:46 +0100 |
commit | 7a7f1b9acb5990b24b8aeea5a435c136bb1bb7db (patch) | |
tree | 438c3e07e61a04f8e4e0a0b6d23abd1797ee2b37 /src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt | |
parent | 5ffe5dab3973b540a4e0cd1b57f13d0be77e3f84 (diff) | |
download | skyhanni-7a7f1b9acb5990b24b8aeea5a435c136bb1bb7db.tar.gz skyhanni-7a7f1b9acb5990b24b8aeea5a435c136bb1bb7db.tar.bz2 skyhanni-7a7f1b9acb5990b24b8aeea5a435c136bb1bb7db.zip |
Fixed non god pod time parsing errors
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt index 82a8532a1..0e4561041 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt @@ -11,7 +11,7 @@ object TimeUtils { millis: Long, biggestUnit: TimeUnit = TimeUnit.YEAR, showMilliSeconds: Boolean = false, - longName: Boolean = false + longName: Boolean = false, ): String { var milliseconds = millis + 999 val map = mutableMapOf<TimeUnit, Int>() @@ -50,9 +50,7 @@ object TimeUtils { fun getMillis(string: String): Long { val matcher = pattern.matcher(string.lowercase().trim()) - if (!matcher.matches()) { - throw RuntimeException("Matcher is null for '$string'") - } + if (!matcher.matches()) return tryAlternativeFormat(string) val years = matcher.group("y")?.toLong() ?: 0L val days = matcher.group("d")?.toLong() ?: 0L @@ -69,6 +67,32 @@ object TimeUtils { return millis } + + private fun tryAlternativeFormat(string: String): Long { + val split = string.split(":") + return when (split.size) { + 3 -> { + val hours = split[0].toInt() * 1000 * 60 * 60 + val minutes = split[1].toInt() * 1000 * 60 + val seconds = split[2].toInt() * 1000 + seconds + minutes + hours + } + + 2 -> { + val minutes = split[0].toInt() * 1000 * 60 + val seconds = split[1].toInt() * 1000 + seconds + minutes + } + + 1 -> { + split[0].toInt() * 1000 + } + + else -> { + throw RuntimeException("Invalid format: '$string'") + } + }.toLong() + } } private const val FACTOR_SECONDS = 1000L |