Compare commits
2 commits
40c53f4313
...
8a2a9564b8
Author | SHA1 | Date | |
---|---|---|---|
8a2a9564b8 | |||
b3ba4e3e99 |
3 changed files with 21 additions and 7 deletions
|
@ -14,7 +14,7 @@ val ownerID = 372703841151614976L
|
|||
group = "net.moonleay.rssbot"
|
||||
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
|
||||
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
|
||||
?: "0.3.1"
|
||||
?: "0.3.3"
|
||||
|
||||
val kordver = "1.5.10-SNAPSHOT"
|
||||
val coroutinesver = "1.7.3"
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.time.LocalDateTime
|
|||
import java.time.format.DateTimeFormatter
|
||||
|
||||
object MessageUtil {
|
||||
private val dtf: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy @ HH:mm:ss")
|
||||
private val dtf: DateTimeFormatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss")
|
||||
|
||||
///Send an embedded message as a reply
|
||||
suspend fun sendEmbedForPublicSlashCommand(
|
||||
|
|
|
@ -20,13 +20,27 @@ package net.moonleay.rssbot.util
|
|||
|
||||
import java.time.ZonedDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.time.format.DateTimeParseException
|
||||
|
||||
|
||||
object TimeUtil {
|
||||
fun getUnixTimeFromStamp(input: String): Long { // Pattern: Sun, 15 Oct 2023 11:04:57 GMT
|
||||
val formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z")
|
||||
try {
|
||||
val formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz")
|
||||
val result = ZonedDateTime.parse(input, formatter).toEpochSecond() * 1000
|
||||
Logger.out("Converted $input to $result")
|
||||
return result
|
||||
} catch (e: DateTimeParseException) {
|
||||
Logger.out("Could not convert $input to unix time, trying other pattern")
|
||||
return try {
|
||||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX")
|
||||
val result = ZonedDateTime.parse(input, formatter).toEpochSecond() * 1000
|
||||
Logger.out("Converted $input to $result")
|
||||
result
|
||||
} catch (e: DateTimeParseException) {
|
||||
Logger.out("Could not convert $input to unix time")
|
||||
0
|
||||
}
|
||||
}
|
||||
} // I'm ashamed of this code. I'm sorry. I don't know how to do it better.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue