compareTo

actual open operator override fun compareTo(other: YearMonth): Int(source)
expect open operator override fun compareTo(other: YearMonth): Int(source)

Compares this date with the other year-month. Returns zero if this year-month represents the same month as the other (meaning they are equal to one other), a negative number if this year-month is earlier than the other, and a positive number if this year-month is later than the other.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlinx.datetime.onDay
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Comparing YearMonth values
check(YearMonth(2023, 4) < YearMonth(2024, 3))
check(YearMonth(2023, 4) < YearMonth(2023, 5))
check(YearMonth(-1000, 4) < YearMonth(0, 4)) 
   //sampleEnd
}
actual open operator override fun compareTo(other: YearMonth): Int(source)