feat: added function to get a ZonedDateTimeObject from a string, added function to generate a cronjob string from a ZonedDateTime object
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
ad6040ebf3
commit
7ab73765e4
1 changed files with 16 additions and 0 deletions
|
@ -20,8 +20,10 @@ package net.moonleay.lilJudd.util
|
||||||
|
|
||||||
import kotlinx.datetime.DayOfWeek
|
import kotlinx.datetime.DayOfWeek
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
|
import java.time.LocalDateTime
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,4 +144,18 @@ object TimeUtil {
|
||||||
return ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(getMondayDayOfMonth()).withHour(4)
|
return ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(getMondayDayOfMonth()).withHour(4)
|
||||||
.withMinute(0).withSecond(0)
|
.withMinute(0).withSecond(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDateFromString(input: String): ZonedDateTime {
|
||||||
|
val formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
|
||||||
|
val localDateTime = LocalDateTime.parse(input, formatter)
|
||||||
|
val zoneId = ZoneId.of("UTC+2") // TODO: Add the possibility to set your timezone
|
||||||
|
return ZonedDateTime.of(localDateTime, zoneId)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCronjobStringFromDate(zdt: ZonedDateTime): String {
|
||||||
|
// I'll have to add the possibility to set your timezone in the future
|
||||||
|
// Only subtracting 1 hour, because I want to run the job 1 hour later
|
||||||
|
val zdt_ = zdt.minusHours(1)
|
||||||
|
return "0 ${zdt_.minute} ${zdt_.hour} ${zdt_.dayOfMonth - 1} ${zdt_.month.value - 1} ${zdt_.year}"// 0o *w"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue