Compare commits

..

2 commits

Author SHA1 Message Date
8a2a9564b8 chore: bump version
Signed-off-by: moonleay <contact@moonleay.net>
2023-10-21 14:56:38 +02:00
b3ba4e3e99 fix!: fixed timestamp not converting correctly
Signed-off-by: moonleay <contact@moonleay.net>
2023-10-21 14:56:26 +02:00
3 changed files with 21 additions and 7 deletions

View file

@ -14,7 +14,7 @@ val ownerID = 372703841151614976L
group = "net.moonleay.rssbot" group = "net.moonleay.rssbot"
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" } version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" } ?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
?: "0.3.1" ?: "0.3.3"
val kordver = "1.5.10-SNAPSHOT" val kordver = "1.5.10-SNAPSHOT"
val coroutinesver = "1.7.3" val coroutinesver = "1.7.3"

View file

@ -29,7 +29,7 @@ import java.time.LocalDateTime
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
object MessageUtil { 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 ///Send an embedded message as a reply
suspend fun sendEmbedForPublicSlashCommand( suspend fun sendEmbedForPublicSlashCommand(

View file

@ -20,13 +20,27 @@ package net.moonleay.rssbot.util
import java.time.ZonedDateTime import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.time.format.DateTimeParseException
object TimeUtil { object TimeUtil {
fun getUnixTimeFromStamp(input: String): Long { // Pattern: Sun, 15 Oct 2023 11:04:57 GMT 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 val result = ZonedDateTime.parse(input, formatter).toEpochSecond() * 1000
Logger.out("Converted $input to $result") Logger.out("Converted $input to $result")
return 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.
}