YearMonthProgression

A progression of values of type YearMonth.

Samples

import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test

fun main() { 
   //sampleStart 
   // Creating YearMonthProgression with a step size other than 1 day
check(
    (YearMonth(2000, 1)..YearMonth(2000, 5)).step(2, DateTimeUnit.MONTH).toList() == listOf(
        YearMonth(2000, 1),
        YearMonth(2000, 3),
        YearMonth(2000, 5)
    ))
check(
    (YearMonth(2000, 5) downTo YearMonth(2000, 1)).step(2, DateTimeUnit.MONTH).toList() == listOf(
        YearMonth(2000, 5),
        YearMonth(2000, 3),
        YearMonth(2000, 1)
    )) 
   //sampleEnd
}
import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test

fun main() { 
   //sampleStart 
   // Creating YearMonthProgression and flipping its direction
check(
    (YearMonth(2000, 1)..YearMonth(2000, 5)).reversed().toList() == listOf(
        YearMonth(2000, 5),
        YearMonth(2000, 4),
        YearMonth(2000, 3),
        YearMonth(2000, 2),
        YearMonth(2000, 1)
    ))
check(
    (YearMonth(2000, 5) downTo YearMonth(2000, 1)).reversed().toList() == listOf(
        YearMonth(2000, 1),
        YearMonth(2000, 2),
        YearMonth(2000, 3),
        YearMonth(2000, 4),
        YearMonth(2000, 5)
    )) 
   //sampleEnd
}
import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test

fun main() { 
   //sampleStart 
   // Getting the first and last elements of a YearMonthProgression
check((YearMonth(2000, 1)..YearMonth(2000, 5)).first() == YearMonth(2000, 1))
check((YearMonth(2000, 1)..YearMonth(2000, 5)).last() == YearMonth(2000, 5))
check((YearMonth(2000, 1)..YearMonth(2000, 6)).step(2, DateTimeUnit.MONTH).first() == YearMonth(2000, 1))
check((YearMonth(2000, 1)..YearMonth(2000, 6)).step(2, DateTimeUnit.MONTH).last() == YearMonth(2000, 5))
check((YearMonth(2000, 5)..YearMonth(2000, 1)).firstOrNull() == null)
check((YearMonth(2000, 5)..YearMonth(2000, 1)).lastOrNull() == null) 
   //sampleEnd
}

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns the first YearMonth of the progression

Link copied to clipboard

Returns the last YearMonth of the progression

Link copied to clipboard
open override val size: Int

Returns the number of months in the progression. Returns Int.MAX_VALUE if the number of months overflows Int

Functions

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

Returns true iff value is a member of the progression.

Link copied to clipboard
open override fun containsAll(elements: Collection<YearMonth>): Boolean

Returns true iff every element in elements is a member of the progression.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
Link copied to clipboard

Returns the first YearMonth of the YearMonthProgression, or null if the progression is empty.

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

Returns true iff the progression contains no values. i.e. first<last if step is positive, or first last if step is negative.

Link copied to clipboard
open operator override fun iterator(): Iterator<YearMonth>

Returns an Iterator that traverses the progression from first to last

Link copied to clipboard
Link copied to clipboard

Returns the last YearMonth of the YearMonthProgression, or null if the progression is empty.

Link copied to clipboard

Returns a random YearMonth within the bounds of the YearMonthProgression.

Link copied to clipboard

Returns a random YearMonth within the bounds of the YearMonthProgression or null if the progression is empty.

Link copied to clipboard

Returns a reversed YearMonthProgression, i.e. one that goes from last to first. The sign of the step is switched, in order to reverse the direction of the progression.

Link copied to clipboard

Returns a YearMonthProgression with the same start and end, but a changed step value.

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

Returns a string representation of the progression. Uses the range operator notation if the progression is increasing, and downTo if it is decreasing. The step is referenced in days.