
commonMain.io.wojciechosak.calendar.utils.CalendarExt.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of calendar-jvm Show documentation
Show all versions of calendar-jvm Show documentation
Kotlin Compose Multiplatform UI library that simplifies usage of calendar views
package io.wojciechosak.calendar.utils
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.Month
fun isLeapYear(year: Int): Boolean {
return try {
LocalDate(year, 2, 29)
true
} catch (exception: IllegalArgumentException) {
false
}
}
fun monthLength(month: Month, year: Int): Int {
val isLeapYear = isLeapYear(year)
return when (month) {
Month.FEBRUARY -> if (isLeapYear) 29 else 28
Month.APRIL, Month.JUNE, Month.SEPTEMBER, Month.NOVEMBER -> 30
else -> 31
}
}
internal fun LocalDateTime.toLocalDate(): LocalDate {
return LocalDate(year, month, dayOfMonth)
}
internal fun LocalDate.copy(
year: Int = this.year,
month: Month = this.month,
day: Int = this.dayOfMonth
): LocalDate {
return LocalDate(year, month, day)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy