From e5e4770346578877b6cc3fe4a8e55037a1190476 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 5 Oct 2019 10:57:11 +0600 Subject: [PATCH] start work with scheduler and remove redundant regexes from CronDateTime --- .../insanusmokrassar/krontab/CronDateTime.kt | 31 +++++++++---------- .../krontab/CronRegularExpression.kt | 2 +- .../insanusmokrassar/krontab/Scheduler.kt | 3 ++ 3 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Scheduler.kt diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronDateTime.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronDateTime.kt index c30e98c..fb14235 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronDateTime.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronDateTime.kt @@ -1,13 +1,10 @@ package com.github.insanusmokrassar.krontab -import com.soywiz.klock.* +import com.github.insanusmokrassar.krontab.utils.* import com.github.insanusmokrassar.krontab.utils.clamp - -private val incomeMonthRange = 0 .. 11 -private val incomeDayOfMonthRange = 0 .. 31 -private val incomeHourRange = 0 .. 23 -private val incomeMinuteRange = 0 .. 59 -private val incomeSecondRange = 0 .. 59 +import com.github.insanusmokrassar.krontab.utils.dayOfMonthRange +import com.github.insanusmokrassar.krontab.utils.monthRange +import com.soywiz.klock.* /** * [month] 0-11 @@ -24,11 +21,11 @@ data class CronDateTime( val seconds: Byte? = null ) { init { - check(month ?.let { it in incomeMonthRange } ?: true) - check(dayOfMonth ?.let { it in incomeDayOfMonthRange } ?: true) - check(hours?.let { it in incomeHourRange } ?: true) - check(minutes?.let { it in incomeMinuteRange } ?: true) - check(seconds?.let { it in incomeSecondRange } ?: true) + check(month ?.let { it in monthRange } ?: true) + check(dayOfMonth ?.let { it in dayOfMonthRange } ?: true) + check(hours?.let { it in hoursRange } ?: true) + check(minutes?.let { it in minutesRange } ?: true) + check(seconds?.let { it in secondsRange } ?: true) } internal val klockDayOfMonth = dayOfMonth ?.plus(1) @@ -41,11 +38,11 @@ data class CronDateTime( minutes: Int? = null, seconds: Int? = null ) = CronDateTime( - month ?.clamp(incomeMonthRange) ?.toByte(), - dayOfMonth ?.clamp(incomeDayOfMonthRange) ?.toByte(), - hours ?.clamp(incomeHourRange) ?.toByte(), - minutes ?.clamp(incomeMinuteRange) ?.toByte(), - seconds ?.clamp(incomeSecondRange) ?.toByte() + month ?.clamp(monthRange) ?.toByte(), + dayOfMonth ?.clamp(dayOfMonthRange) ?.toByte(), + hours ?.clamp(hoursRange) ?.toByte(), + minutes ?.clamp(minutesRange) ?.toByte(), + seconds ?.clamp(secondsRange) ?.toByte() ) } } diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronRegularExpression.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronRegularExpression.kt index 029747c..5cd8217 100644 --- a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronRegularExpression.kt +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/CronRegularExpression.kt @@ -12,7 +12,7 @@ internal val minutesRegex = Regex("[*]|((${minutesOrSecondsNumberRegex.pattern}) internal val secondsRegex = minutesRegex internal val monthRange = 0 .. 11 -internal val dayOfMonthRange = 0 .. 31 +internal val dayOfMonthRange = 0 .. 30 internal val hoursRange = 0 .. 23 internal val minutesRange = 0 .. 59 internal val secondsRange = minutesRange diff --git a/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Scheduler.kt b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Scheduler.kt new file mode 100644 index 0000000..8a710c0 --- /dev/null +++ b/src/commonMain/kotlin/com/github/insanusmokrassar/krontab/Scheduler.kt @@ -0,0 +1,3 @@ +package com.github.insanusmokrassar.krontab + +