feat: added JSON deformatter to TimeUtil
Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
parent
cc41445d2f
commit
e354ed9143
1 changed files with 15 additions and 2 deletions
|
@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
object TimeUtil {
|
object TimeUtil {
|
||||||
|
|
||||||
fun getTimeFormatedShortend(time2: Long): String {
|
fun getTimeFormatedShortend(time2: Long, showS: Boolean): String {
|
||||||
var time = time2
|
var time = time2
|
||||||
val days: Long = TimeUnit.MILLISECONDS
|
val days: Long = TimeUnit.MILLISECONDS
|
||||||
.toDays(time)
|
.toDays(time)
|
||||||
|
@ -52,7 +52,7 @@ object TimeUtil {
|
||||||
if (minutes >= 1) {
|
if (minutes >= 1) {
|
||||||
s += minutes.toString() + "m "
|
s += minutes.toString() + "m "
|
||||||
}
|
}
|
||||||
if (seconds >= 1 && hours < 1) {
|
if (seconds >= 1 && hours < 1 && showS) {
|
||||||
s += seconds.toString() + "s"
|
s += seconds.toString() + "s"
|
||||||
}
|
}
|
||||||
if (s.isEmpty() || s.isBlank()) {
|
if (s.isEmpty() || s.isBlank()) {
|
||||||
|
@ -158,4 +158,17 @@ object TimeUtil {
|
||||||
val zdt_ = zdt.minusHours(1)
|
val zdt_ = zdt.minusHours(1)
|
||||||
return "0 ${zdt_.minute} ${zdt_.hour} ${zdt_.dayOfMonth - 1} ${zdt_.month.value - 1} ${zdt_.year}"// 0o *w"
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue