feat: added JSON deformatter to TimeUtil

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2023-10-05 11:40:16 +02:00
parent cc41445d2f
commit e354ed9143

View file

@ -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)
}
}