diff --git a/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt b/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt index 7e5fbec..c3c3e54 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt @@ -20,8 +20,10 @@ package net.moonleay.lilJudd.util import kotlinx.datetime.DayOfWeek import java.time.Duration +import java.time.LocalDateTime import java.time.ZoneId import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter import java.util.concurrent.TimeUnit @@ -142,4 +144,18 @@ object TimeUtil { return ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(getMondayDayOfMonth()).withHour(4) .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" + } }