feat: added new JSON time getter

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2024-01-19 22:41:52 +01:00
parent 58f2379f45
commit 05b4dc39b5
Signed by: moonleay
GPG key ID: 82667543CCD715FB

View file

@ -1,6 +1,6 @@
/* /*
* lilJudd * lilJudd
* Copyright (C) 2023 moonleay * Copyright (C) 2024 moonleay
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -177,6 +177,24 @@ object TimeUtil {
return ZonedDateTime.of(localDateTime, zoneId).toEpochSecond() * 1000 return ZonedDateTime.of(localDateTime, zoneId).toEpochSecond() * 1000
} }
fun getTimeFromJSONTime(inp: String, zone: String): String {
// 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
val returnFormat = DateTimeFormatter.ofPattern("HH:mm")
return ZonedDateTime.of(localDateTime, zoneId).format(returnFormat)
}
fun getTimeFromJSONTimeLong(inp: String, zone: String): String {
// 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
val returnFormat = DateTimeFormatter.ofPattern("dd'/'MM',' HH:mm")
return ZonedDateTime.of(localDateTime, zoneId).format(returnFormat)
}
fun getTimeDifferenceFormatted(start: Long, end: Long): String { fun getTimeDifferenceFormatted(start: Long, end: Long): String {
val diff = end - start val diff = end - start
return getTimeFormatedShortend(diff, false) return getTimeFormatedShortend(diff, false)