All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fuookami.ospf.kotlin.utils.functional.DateTimeRange.kt Maven / Gradle / Ivy

There is a newer version: 1.0.29
Show newest version
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
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy