fuookami.ospf.kotlin.utils.functional.DateTimeRange.kt Maven / Gradle / Ivy
package fuookami.ospf.kotlin.utils.functional
import kotlinx.datetime.*
class LocalDateClosedRangeIterator(
private var current: LocalDate,
private val range: ClosedRange,
private val step: DatePeriod
) : Iterator {
override fun hasNext(): Boolean {
return current <= range.endInclusive
}
override fun next(): LocalDate {
val next = current
current += step
return next
}
}
fun ClosedRange.iterator(step: DatePeriod): Iterator {
return LocalDateClosedRangeIterator(
this.start,
this,
step
)
}
class LocalDateOpenEndRangeIterator(
private var current: LocalDate,
val range: OpenEndRange,
val step: DatePeriod
) : Iterator {
override fun hasNext(): Boolean {
return current < range.endExclusive
}
override fun next(): LocalDate {
val next = current
current += step
return next
}
}
fun OpenEndRange.iterator(step: DatePeriod): Iterator {
return LocalDateOpenEndRangeIterator(
this.start,
this,
step
)
}