forked from DiscordBots/lilJudd
feat: added new JSON time getter
Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
parent
58f2379f45
commit
05b4dc39b5
1 changed files with 19 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue