From 05b4dc39b51c045eb4849c4c9e62b2e66cd223bf Mon Sep 17 00:00:00 2001 From: moonleay Date: Fri, 19 Jan 2024 22:41:52 +0100 Subject: [PATCH] feat: added new JSON time getter Signed-off-by: moonleay --- .../net/moonleay/lilJudd/util/TimeUtil.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt b/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt index dba203c..acf0da8 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt @@ -1,6 +1,6 @@ /* * lilJudd - * Copyright (C) 2023 moonleay + * Copyright (C) 2024 moonleay * * 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 @@ -177,6 +177,24 @@ object TimeUtil { 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 { val diff = end - start return getTimeFormatedShortend(diff, false)