diff --git a/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt b/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt index c3c3e54..5287bc3 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt @@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit object TimeUtil { - fun getTimeFormatedShortend(time2: Long): String { + fun getTimeFormatedShortend(time2: Long, showS: Boolean): String { var time = time2 val days: Long = TimeUnit.MILLISECONDS .toDays(time) @@ -52,7 +52,7 @@ object TimeUtil { if (minutes >= 1) { s += minutes.toString() + "m " } - if (seconds >= 1 && hours < 1) { + if (seconds >= 1 && hours < 1 && showS) { s += seconds.toString() + "s" } if (s.isEmpty() || s.isBlank()) { @@ -158,4 +158,17 @@ object TimeUtil { val zdt_ = zdt.minusHours(1) return "0 ${zdt_.minute} ${zdt_.hour} ${zdt_.dayOfMonth - 1} ${zdt_.month.value - 1} ${zdt_.year}"// 0o *w" } + + fun deformatJSONTime(inp: String, zone: String): Long { + // 2023-10-05T08:00:00Z + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'") + val localDateTime = LocalDateTime.parse(inp, formatter) + val zoneId = ZoneId.of(zone) // TODO: Add the possibility to set your timezone + return ZonedDateTime.of(localDateTime, zoneId).toEpochSecond() * 1000 + } + + fun getTimeDifferenceFormatted(start: Long, end: Long): String { + val diff = end - start + return getTimeFormatedShortend(diff, false) + } }