2019-10-04 18:04:00 +00:00
|
|
|
package com.github.insanusmokrassar.krontab
|
|
|
|
|
2019-10-05 04:57:11 +00:00
|
|
|
import com.github.insanusmokrassar.krontab.utils.*
|
2019-10-04 18:04:00 +00:00
|
|
|
import com.github.insanusmokrassar.krontab.utils.clamp
|
2019-10-05 04:57:11 +00:00
|
|
|
import com.github.insanusmokrassar.krontab.utils.dayOfMonthRange
|
|
|
|
import com.github.insanusmokrassar.krontab.utils.monthRange
|
|
|
|
import com.soywiz.klock.*
|
2019-10-04 18:04:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [month] 0-11
|
|
|
|
* [dayOfMonth] 0-31
|
2019-10-04 18:09:39 +00:00
|
|
|
* [hours] 0-23
|
|
|
|
* [minutes] 0-59
|
|
|
|
* [seconds] 0-59
|
2019-10-04 18:04:00 +00:00
|
|
|
*/
|
|
|
|
data class CronDateTime(
|
|
|
|
val month: Byte? = null,
|
|
|
|
val dayOfMonth: Byte? = null,
|
2019-10-04 18:09:39 +00:00
|
|
|
val hours: Byte? = null,
|
|
|
|
val minutes: Byte? = null,
|
|
|
|
val seconds: Byte? = null
|
2019-10-04 18:04:00 +00:00
|
|
|
) {
|
|
|
|
init {
|
2019-10-05 04:57:11 +00:00
|
|
|
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)
|
2019-10-04 18:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
internal val klockDayOfMonth = dayOfMonth ?.plus(1)
|
2019-10-05 04:55:01 +00:00
|
|
|
|
|
|
|
companion object {
|
|
|
|
fun create(
|
|
|
|
month: Int? = null,
|
|
|
|
dayOfMonth: Int? = null,
|
|
|
|
hours: Int? = null,
|
|
|
|
minutes: Int? = null,
|
|
|
|
seconds: Int? = null
|
|
|
|
) = CronDateTime(
|
2019-10-05 04:57:11 +00:00
|
|
|
month ?.clamp(monthRange) ?.toByte(),
|
|
|
|
dayOfMonth ?.clamp(dayOfMonthRange) ?.toByte(),
|
|
|
|
hours ?.clamp(hoursRange) ?.toByte(),
|
|
|
|
minutes ?.clamp(minutesRange) ?.toByte(),
|
|
|
|
seconds ?.clamp(secondsRange) ?.toByte()
|
2019-10-05 04:55:01 +00:00
|
|
|
)
|
|
|
|
}
|
2019-10-04 18:04:00 +00:00
|
|
|
}
|