Year Month Range
class YearMonthRange(start: YearMonth, endInclusive: YearMonth) : YearMonthProgression, ClosedRange<YearMonth> , OpenEndRange<YearMonth> (source)
A range of values of type YearMonth.
Samples
import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test
fun main() {
//sampleStart
// Creating YearMonthRange from YearMonth
check((YearMonth(2000, 1)..YearMonth(2000, 5)).toList() == listOf(
YearMonth(2000, 1),
YearMonth(2000, 2),
YearMonth(2000, 3),
YearMonth(2000, 4),
YearMonth(2000, 5)
))
check(
(YearMonth(2000, 1)..<YearMonth(2000, 6)).toList() == listOf(
YearMonth(2000, 1),
YearMonth(2000, 2),
YearMonth(2000, 3),
YearMonth(2000, 4),
YearMonth(2000, 5)
))
check(
(YearMonth(2000, 5) downTo YearMonth(2000, 1)).toList() == listOf(
YearMonth(2000, 5),
YearMonth(2000, 4),
YearMonth(2000, 3),
YearMonth(2000, 2),
YearMonth(2000, 1)
))
//sampleEnd
}