add "every" and "upTo" infix functions in time builder

This commit is contained in:
InsanusMokrassar 2019-10-10 15:50:20 +06:00
parent b9bb7f3373
commit b93b9fd7c7
2 changed files with 3 additions and 9 deletions

View File

@ -12,14 +12,6 @@ fun buildSchedule(settingsBlock: SchedulerBuilder.() -> Unit): CronDateTimeSched
return builder.build()
}
//infix fun Int.withStep(step: Int): PropertyHolder {
// return DivPropertyHolder(this, step)
//}
//
//operator fun Int.minus(including: Int): PropertyHolder {
// return RangePropertyHolder(this, including)
//}
class SchedulerBuilder(
private var seconds: Array<Byte>? = null,
private var minutes: Array<Byte>? = null,

View File

@ -21,7 +21,7 @@ sealed class TimeBuilder (
result = (result ?: emptySet()) + value.clamp(restrictionsRange)
}
inline infix fun from(value: Int) = value
inline fun from(value: Int) = value
infix fun Int.every(delay: Int): Array<Int> {
val progression = clamp(restrictionsRange) .. restrictionsRange.last step delay
@ -31,6 +31,7 @@ sealed class TimeBuilder (
return result
}
infix fun every(delay: Int): Array<Int> = 0 every delay
infix fun Int.upTo(endIncluding: Int): Array<Int> {
val progression = clamp(restrictionsRange) .. endIncluding.clamp(restrictionsRange)
@ -40,6 +41,7 @@ sealed class TimeBuilder (
return result
}
infix fun upTo(endIncluding: Int): Array<Int> = 0 upTo endIncluding
internal fun build() = result ?.map { it.toByte() } ?.toTypedArray()
}