YearMonthRange

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
}

Constructors

Link copied to clipboard
constructor(start: YearMonth, endInclusive: YearMonth)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val endInclusive: YearMonth

Returns the upper bound of the range, inclusive.

Link copied to clipboard
open override val start: YearMonth

Returns the lower bound of the range, inclusive.

Functions

Link copied to clipboard
open operator override fun contains(value: YearMonth): Boolean

Returns true iff value is contained within the range. i.e. value is between start and endInclusive.

Link copied to clipboard
open override fun isEmpty(): Boolean

Returns true iff there are no months contained within the range.

Link copied to clipboard
open override fun toString(): String

Returns a string representation of the range using the range operator notation.