feat!: removed unused funcs, added getUnixTimeFromStamp

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2023-10-15 15:30:37 +02:00
parent 0c7f51ba72
commit d60b7ba92f

View file

@ -18,47 +18,13 @@
package net.moonleay.rssbot.util package net.moonleay.rssbot.util
import kotlinx.datetime.DayOfWeek
import java.time.ZonedDateTime import java.time.ZonedDateTime
import java.util.concurrent.TimeUnit import java.time.format.DateTimeFormatter
object TimeUtil { object TimeUtil {
fun getUnixTimeFromStamp(input: String): Long { // Pattern: Sun, 15 Oct 2023 11:04:57 GMT
fun getTimeFormatedShortend(time2: Long, showS: Boolean): String { val formatter = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss z")
var time = time2 return ZonedDateTime.parse(input, formatter).toEpochSecond() * 1000
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
} }
} }