Month
The enumeration class representing the 12 months of the year.
Can be acquired from LocalDate.month or constructed using the Month
factory function that accepts the month number. This number can be obtained from the number property.
Samples
import kotlinx.datetime.*
import kotlin.test.*
fun main() {
//sampleStart
// Providing different behavior based on what month it is today
val today = Clock.System.todayIn(TimeZone.currentSystemDefault())
when (today.month) {
Month.JANUARY -> check(today.month.number == 1)
Month.FEBRUARY -> check(today.month.number == 2)
Month.MARCH -> check(today.month.number == 3)
Month.APRIL -> check(today.month.number == 4)
Month.MAY -> check(today.month.number == 5)
Month.JUNE -> check(today.month.number == 6)
Month.JULY -> check(today.month.number == 7)
Month.AUGUST -> check(today.month.number == 8)
Month.SEPTEMBER -> check(today.month.number == 9)
Month.OCTOBER -> check(today.month.number == 10)
Month.NOVEMBER -> check(today.month.number == 11)
Month.DECEMBER -> check(today.month.number == 12)
else -> TODO("A new month was added to the calendar?")
}
//sampleEnd
}