From d60b7ba92f762ba3c46066f3aaaf1533401881f4 Mon Sep 17 00:00:00 2001 From: moonleay Date: Sun, 15 Oct 2023 15:30:37 +0200 Subject: [PATCH] feat!: removed unused funcs, added getUnixTimeFromStamp Signed-off-by: moonleay --- .../net/moonleay/rssbot/util/TimeUtil.kt | 42 ++----------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/src/main/kotlin/net/moonleay/rssbot/util/TimeUtil.kt b/src/main/kotlin/net/moonleay/rssbot/util/TimeUtil.kt index 89ff4b8..416d3a6 100644 --- a/src/main/kotlin/net/moonleay/rssbot/util/TimeUtil.kt +++ b/src/main/kotlin/net/moonleay/rssbot/util/TimeUtil.kt @@ -18,47 +18,13 @@ package net.moonleay.rssbot.util -import kotlinx.datetime.DayOfWeek import java.time.ZonedDateTime -import java.util.concurrent.TimeUnit +import java.time.format.DateTimeFormatter object TimeUtil { - - fun getTimeFormatedShortend(time2: Long, showS: Boolean): String { - var time = time2 - val days: Long = TimeUnit.MILLISECONDS - .toDays(time) - time -= TimeUnit.DAYS.toMillis(days) - val hours: Long = TimeUnit.MILLISECONDS - .toHours(time) - time -= TimeUnit.HOURS.toMillis(hours) - val minutes: Long = TimeUnit.MILLISECONDS - .toMinutes(time) - time -= TimeUnit.MINUTES.toMillis(minutes) - val seconds: Long = TimeUnit.MILLISECONDS - .toSeconds(time) - var s = "" - if (days >= 1) { - s += days.toString() + "d " - } - if (hours >= 1) { - s += hours.toString() + "h " - } - if (minutes >= 1) { - s += minutes.toString() + "m " - } - if (seconds >= 1 && hours < 1 && showS) { - s += seconds.toString() + "s" - } - if (s.isEmpty() || s.isBlank()) { - s = "None" - } - return s - } - - // Returns the day of the month of the monday of this week - fun getMondayDayOfMonth(): Int { - return ZonedDateTime.now().with(DayOfWeek.MONDAY).dayOfMonth + 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") + return ZonedDateTime.parse(input, formatter).toEpochSecond() * 1000 } }