From 8bca3838bc3e1be2246528b043e0a4746e56524a Mon Sep 17 00:00:00 2001 From: limited_dev Date: Wed, 28 Jun 2023 22:39:15 +0200 Subject: [PATCH] feat: split getDelay function into three different getDelay functions Signed-off-by: limited_dev --- .../net/moonleay/lilJudd/util/TimeUtil.kt | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt b/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt index 1edfe17..7e5fbec 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/util/TimeUtil.kt @@ -18,7 +18,10 @@ package net.moonleay.lilJudd.util +import kotlinx.datetime.DayOfWeek import java.time.Duration +import java.time.ZoneId +import java.time.ZonedDateTime import java.util.concurrent.TimeUnit @@ -123,7 +126,20 @@ object TimeUtil { } } - fun getDelay(day: String): Int { - return DaysUntilMonday[day]!! + + // Returns the day of the month of the monday of this week + fun getMondayDayOfMonth(): Int { + return ZonedDateTime.now().with(DayOfWeek.MONDAY).dayOfMonth + } + + // Returns the day of the week as an int. Monday = 0; Sunday = 6 + fun getDayOfMonthInt(dow: DayOfWeek): Int { + return dow.value + } + + // Returns the day of the month of the monday of the current week + fun getWeekStamp(): ZonedDateTime { + return ZonedDateTime.now(ZoneId.of("Europe/Berlin")).withDayOfMonth(getMondayDayOfMonth()).withHour(4) + .withMinute(0).withSecond(0) } }