diff --git a/compose-multiplatform/library/api/android/library.api b/compose-multiplatform/library/api/android/library.api index 5eca3398..a64c47e0 100644 --- a/compose-multiplatform/library/api/android/library.api +++ b/compose-multiplatform/library/api/android/library.api @@ -173,7 +173,6 @@ public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarSta } public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState$Companion { - public final fun getSaver ()Landroidx/compose/runtime/saveable/Saver; } public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarStateKt { @@ -222,18 +221,11 @@ public final class com/kizitonwose/calendar/core/DayPosition : java/lang/Enum { } public final class com/kizitonwose/calendar/core/ExtensionsKt { - public static final fun atDay (Lcom/kizitonwose/calendar/core/YearMonth;I)Lkotlinx/datetime/LocalDate; - public static final fun atEndOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lkotlinx/datetime/LocalDate; - public static final fun atStartOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lkotlinx/datetime/LocalDate; public static final fun daysOfWeek (Ljava/time/DayOfWeek;)Ljava/util/List; public static synthetic fun daysOfWeek$default (Ljava/time/DayOfWeek;ILjava/lang/Object;)Ljava/util/List; - public static final fun getNextMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lcom/kizitonwose/calendar/core/YearMonth; - public static final fun getPreviousMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lcom/kizitonwose/calendar/core/YearMonth; public static final fun getYearMonth (Lkotlinx/datetime/LocalDate;)Lcom/kizitonwose/calendar/core/YearMonth; - public static final fun minusMonths (Lcom/kizitonwose/calendar/core/YearMonth;I)Lcom/kizitonwose/calendar/core/YearMonth; - public static final fun now (Lcom/kizitonwose/calendar/core/YearMonth$Companion;)Lcom/kizitonwose/calendar/core/YearMonth; - public static final fun now (Lkotlinx/datetime/LocalDate$Companion;)Lkotlinx/datetime/LocalDate; - public static final fun plusMonths (Lcom/kizitonwose/calendar/core/YearMonth;I)Lcom/kizitonwose/calendar/core/YearMonth; + public static final fun now (Lkotlinx/datetime/LocalDate$Companion;Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;)Lkotlinx/datetime/LocalDate; + public static synthetic fun now$default (Lkotlinx/datetime/LocalDate$Companion;Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;ILjava/lang/Object;)Lkotlinx/datetime/LocalDate; } public final class com/kizitonwose/calendar/core/Extensions_jvmKt { @@ -302,6 +294,18 @@ public final class com/kizitonwose/calendar/core/YearMonth : java/io/Serializabl } public final class com/kizitonwose/calendar/core/YearMonth$Companion { + public final fun now (Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;)Lcom/kizitonwose/calendar/core/YearMonth; + public static synthetic fun now$default (Lcom/kizitonwose/calendar/core/YearMonth$Companion;Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;ILjava/lang/Object;)Lcom/kizitonwose/calendar/core/YearMonth; +} + +public final class com/kizitonwose/calendar/core/YearMonthKt { + public static final fun atDay (Lcom/kizitonwose/calendar/core/YearMonth;I)Lkotlinx/datetime/LocalDate; + public static final fun atEndOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lkotlinx/datetime/LocalDate; + public static final fun atStartOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lkotlinx/datetime/LocalDate; + public static final fun lengthOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)I + public static final fun minus (Lcom/kizitonwose/calendar/core/YearMonth;ILkotlinx/datetime/DateTimeUnit$MonthBased;)Lcom/kizitonwose/calendar/core/YearMonth; + public static final fun monthsUntil (Lcom/kizitonwose/calendar/core/YearMonth;Lcom/kizitonwose/calendar/core/YearMonth;)I + public static final fun plus (Lcom/kizitonwose/calendar/core/YearMonth;ILkotlinx/datetime/DateTimeUnit$MonthBased;)Lcom/kizitonwose/calendar/core/YearMonth; } public final class com/kizitonwose/calendar/data/WeekData { diff --git a/compose-multiplatform/library/api/desktop/library.api b/compose-multiplatform/library/api/desktop/library.api index b4a70081..87fdf312 100644 --- a/compose-multiplatform/library/api/desktop/library.api +++ b/compose-multiplatform/library/api/desktop/library.api @@ -173,7 +173,6 @@ public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarSta } public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState$Companion { - public final fun getSaver ()Landroidx/compose/runtime/saveable/Saver; } public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarStateKt { @@ -222,18 +221,11 @@ public final class com/kizitonwose/calendar/core/DayPosition : java/lang/Enum { } public final class com/kizitonwose/calendar/core/ExtensionsKt { - public static final fun atDay (Lcom/kizitonwose/calendar/core/YearMonth;I)Lkotlinx/datetime/LocalDate; - public static final fun atEndOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lkotlinx/datetime/LocalDate; - public static final fun atStartOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lkotlinx/datetime/LocalDate; public static final fun daysOfWeek (Ljava/time/DayOfWeek;)Ljava/util/List; public static synthetic fun daysOfWeek$default (Ljava/time/DayOfWeek;ILjava/lang/Object;)Ljava/util/List; - public static final fun getNextMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lcom/kizitonwose/calendar/core/YearMonth; - public static final fun getPreviousMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lcom/kizitonwose/calendar/core/YearMonth; public static final fun getYearMonth (Lkotlinx/datetime/LocalDate;)Lcom/kizitonwose/calendar/core/YearMonth; - public static final fun minusMonths (Lcom/kizitonwose/calendar/core/YearMonth;I)Lcom/kizitonwose/calendar/core/YearMonth; - public static final fun now (Lcom/kizitonwose/calendar/core/YearMonth$Companion;)Lcom/kizitonwose/calendar/core/YearMonth; - public static final fun now (Lkotlinx/datetime/LocalDate$Companion;)Lkotlinx/datetime/LocalDate; - public static final fun plusMonths (Lcom/kizitonwose/calendar/core/YearMonth;I)Lcom/kizitonwose/calendar/core/YearMonth; + public static final fun now (Lkotlinx/datetime/LocalDate$Companion;Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;)Lkotlinx/datetime/LocalDate; + public static synthetic fun now$default (Lkotlinx/datetime/LocalDate$Companion;Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;ILjava/lang/Object;)Lkotlinx/datetime/LocalDate; } public final class com/kizitonwose/calendar/core/Extensions_jvmKt { @@ -302,6 +294,18 @@ public final class com/kizitonwose/calendar/core/YearMonth : java/io/Serializabl } public final class com/kizitonwose/calendar/core/YearMonth$Companion { + public final fun now (Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;)Lcom/kizitonwose/calendar/core/YearMonth; + public static synthetic fun now$default (Lcom/kizitonwose/calendar/core/YearMonth$Companion;Lkotlinx/datetime/Clock;Lkotlinx/datetime/TimeZone;ILjava/lang/Object;)Lcom/kizitonwose/calendar/core/YearMonth; +} + +public final class com/kizitonwose/calendar/core/YearMonthKt { + public static final fun atDay (Lcom/kizitonwose/calendar/core/YearMonth;I)Lkotlinx/datetime/LocalDate; + public static final fun atEndOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lkotlinx/datetime/LocalDate; + public static final fun atStartOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)Lkotlinx/datetime/LocalDate; + public static final fun lengthOfMonth (Lcom/kizitonwose/calendar/core/YearMonth;)I + public static final fun minus (Lcom/kizitonwose/calendar/core/YearMonth;ILkotlinx/datetime/DateTimeUnit$MonthBased;)Lcom/kizitonwose/calendar/core/YearMonth; + public static final fun monthsUntil (Lcom/kizitonwose/calendar/core/YearMonth;Lcom/kizitonwose/calendar/core/YearMonth;)I + public static final fun plus (Lcom/kizitonwose/calendar/core/YearMonth;ILkotlinx/datetime/DateTimeUnit$MonthBased;)Lcom/kizitonwose/calendar/core/YearMonth; } public final class com/kizitonwose/calendar/data/WeekData { diff --git a/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt b/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt index 4c2b7c09..22016034 100644 --- a/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt +++ b/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt @@ -265,7 +265,7 @@ public class WeekCalendarState internal constructor( } public companion object { - public val Saver: Saver = listSaver( + internal val Saver: Saver = listSaver( save = { listOf( it.startDate.toJvmSerializableLocalDate(), diff --git a/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/core/Extensions.kt b/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/core/Extensions.kt index 7c40c5d5..71fcd83f 100644 --- a/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/core/Extensions.kt +++ b/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/core/Extensions.kt @@ -6,12 +6,10 @@ import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.DayOfWeek import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone -import kotlinx.datetime.daysUntil import kotlinx.datetime.isoDayNumber import kotlinx.datetime.minus -import kotlinx.datetime.monthsUntil import kotlinx.datetime.plus -import kotlinx.datetime.toLocalDateTime +import kotlinx.datetime.todayIn import kotlinx.datetime.until /** @@ -32,33 +30,26 @@ public fun daysOfWeek(firstDayOfWeek: DayOfWeek = firstDayOfWeekFromLocale()): L */ public expect fun firstDayOfWeekFromLocale(locale: Locale = Locale.current): DayOfWeek -public fun YearMonth.atStartOfMonth(): LocalDate = atDay(1) - -public fun YearMonth.atEndOfMonth(): LocalDate = atDay(lengthOfMonth()) - -public fun YearMonth.atDay(day: Int): LocalDate = LocalDate(year, month, day) - -public val YearMonth.nextMonth: YearMonth - get() = this.plusMonths(1) - -public val YearMonth.previousMonth: YearMonth - get() = this.minusMonths(1) - -public fun LocalDate.Companion.now(): LocalDate = Clock.System.now() - .toLocalDateTime(TimeZone.currentSystemDefault()) - .date - -public fun YearMonth.Companion.now(): YearMonth = LocalDate.now().yearMonth - -public fun YearMonth.plusMonths(value: Int): YearMonth = - atStartOfMonth().plusMonths(value).yearMonth - -public fun YearMonth.minusMonths(value: Int): YearMonth = - atStartOfMonth().minusMonths(value).yearMonth +/** + * Obtains the current [LocalDate] from the specified [clock] and [timeZone]. + * + * Using this method allows the use of an alternate clock or timezone for testing. + */ +public fun LocalDate.Companion.now( + clock: Clock = Clock.System, + timeZone: TimeZone = TimeZone.currentSystemDefault(), +): LocalDate = clock.todayIn(timeZone) +/** + * Returns the [YearMonth] value for this date. + */ public val LocalDate.yearMonth: YearMonth get() = YearMonth(year, month) +internal fun YearMonth.plusMonths(value: Int): YearMonth = plus(value, DateTimeUnit.MONTH) + +internal fun YearMonth.minusMonths(value: Int): YearMonth = minus(value, DateTimeUnit.MONTH) + internal fun LocalDate.plusDays(value: Int): LocalDate = plus(value, DateTimeUnit.DAY) internal fun LocalDate.minusDays(value: Int): LocalDate = minus(value, DateTimeUnit.DAY) @@ -71,15 +62,6 @@ internal fun LocalDate.plusMonths(value: Int): LocalDate = plus(value, DateTimeU internal fun LocalDate.minusMonths(value: Int): LocalDate = minus(value, DateTimeUnit.MONTH) -internal fun YearMonth.lengthOfMonth(): Int { - val thisMonthStart = atStartOfMonth() - val nextMonthStart = thisMonthStart.plusMonths(1) - return thisMonthStart.daysUntil(nextMonthStart) -} - -internal fun YearMonth.monthsUntil(other: YearMonth): Int = - atStartOfMonth().monthsUntil(other.atStartOfMonth()) - internal fun LocalDate.weeksUntil(other: LocalDate): Int = until(other, DateTimeUnit.WEEK) diff --git a/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/core/YearMonth.kt b/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/core/YearMonth.kt index 03e1fcea..61e2af50 100644 --- a/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/core/YearMonth.kt +++ b/compose-multiplatform/library/src/commonMain/kotlin/com/kizitonwose/calendar/core/YearMonth.kt @@ -1,8 +1,17 @@ package com.kizitonwose.calendar.core import androidx.compose.runtime.Immutable +import kotlinx.datetime.Clock +import kotlinx.datetime.DateTimeArithmeticException +import kotlinx.datetime.DateTimeUnit +import kotlinx.datetime.LocalDate import kotlinx.datetime.Month +import kotlinx.datetime.TimeZone +import kotlinx.datetime.daysUntil +import kotlinx.datetime.minus +import kotlinx.datetime.monthsUntil import kotlinx.datetime.number +import kotlinx.datetime.plus @Immutable public data class YearMonth(val year: Int, val month: Month) : Comparable, JvmSerializable { @@ -13,7 +22,7 @@ public data class YearMonth(val year: Int, val month: Month) : Comparable week.map { dayOffset -> getDay(dayOffset) } }) diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/ContinuousSelectionHelper.kt b/compose-multiplatform/sample/src/commonMain/kotlin/ContinuousSelectionHelper.kt index d75d2cc2..e8fdaabb 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/ContinuousSelectionHelper.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/ContinuousSelectionHelper.kt @@ -1,7 +1,5 @@ import com.kizitonwose.calendar.core.atEndOfMonth import com.kizitonwose.calendar.core.atStartOfMonth -import com.kizitonwose.calendar.core.nextMonth -import com.kizitonwose.calendar.core.previousMonth import com.kizitonwose.calendar.core.yearMonth import kotlinx.datetime.LocalDate import kotlinx.datetime.daysUntil @@ -48,7 +46,7 @@ object ContinuousSelectionHelper { ): Boolean { if (startDate.yearMonth == endDate.yearMonth) return false if (inDate.yearMonth == startDate.yearMonth) return true - val firstDateInThisMonth = inDate.yearMonth.nextMonth.atStartOfMonth() + val firstDateInThisMonth = inDate.yearMonth.next.atStartOfMonth() return firstDateInThisMonth in startDate..endDate && startDate != firstDateInThisMonth } @@ -59,7 +57,7 @@ object ContinuousSelectionHelper { ): Boolean { if (startDate.yearMonth == endDate.yearMonth) return false if (outDate.yearMonth == endDate.yearMonth) return true - val lastDateInThisMonth = outDate.yearMonth.previousMonth.atEndOfMonth() + val lastDateInThisMonth = outDate.yearMonth.previous.atEndOfMonth() return lastDateInThisMonth in startDate..endDate && endDate != lastDateInThisMonth } } diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/Example1Page.kt b/compose-multiplatform/sample/src/commonMain/kotlin/Example1Page.kt index f6e147ca..23a58cb0 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/Example1Page.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/Example1Page.kt @@ -27,11 +27,6 @@ import com.kizitonwose.calendar.core.CalendarDay import com.kizitonwose.calendar.core.DayPosition import com.kizitonwose.calendar.core.YearMonth import com.kizitonwose.calendar.core.daysOfWeek -import com.kizitonwose.calendar.core.minusMonths -import com.kizitonwose.calendar.core.nextMonth -import com.kizitonwose.calendar.core.now -import com.kizitonwose.calendar.core.plusMonths -import com.kizitonwose.calendar.core.previousMonth import kotlinx.coroutines.launch import kotlinx.datetime.DayOfWeek import org.jetbrains.compose.ui.tooling.preview.Preview @@ -61,12 +56,12 @@ fun Example1Page(adjacentMonths: Int = 500) { currentMonth = visibleMonth.yearMonth, goToPrevious = { coroutineScope.launch { - state.animateScrollToMonth(state.firstVisibleMonth.yearMonth.previousMonth) + state.animateScrollToMonth(state.firstVisibleMonth.yearMonth.previous) } }, goToNext = { coroutineScope.launch { - state.animateScrollToMonth(state.firstVisibleMonth.yearMonth.nextMonth) + state.animateScrollToMonth(state.firstVisibleMonth.yearMonth.next) } }, ) diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/Example2Page.kt b/compose-multiplatform/sample/src/commonMain/kotlin/Example2Page.kt index a050dd56..c8356c50 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/Example2Page.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/Example2Page.kt @@ -46,7 +46,6 @@ import com.kizitonwose.calendar.core.DayPosition import com.kizitonwose.calendar.core.YearMonth import com.kizitonwose.calendar.core.daysOfWeek import com.kizitonwose.calendar.core.now -import com.kizitonwose.calendar.core.plusMonths import kotlinx.datetime.DayOfWeek import kotlinx.datetime.LocalDate import org.jetbrains.compose.ui.tooling.preview.Preview diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/Example3Page.kt b/compose-multiplatform/sample/src/commonMain/kotlin/Example3Page.kt index 1e59242d..492f5685 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/Example3Page.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/Example3Page.kt @@ -1,4 +1,3 @@ - import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border @@ -49,11 +48,6 @@ import com.kizitonwose.calendar.core.DayPosition import com.kizitonwose.calendar.core.OutDateStyle import com.kizitonwose.calendar.core.YearMonth import com.kizitonwose.calendar.core.daysOfWeek -import com.kizitonwose.calendar.core.minusMonths -import com.kizitonwose.calendar.core.nextMonth -import com.kizitonwose.calendar.core.now -import com.kizitonwose.calendar.core.plusMonths -import com.kizitonwose.calendar.core.previousMonth import kotlinx.coroutines.launch import kotlinx.datetime.DayOfWeek import org.jetbrains.compose.ui.tooling.preview.Preview @@ -107,12 +101,12 @@ fun Example3Page(close: () -> Unit = {}) { currentMonth = visibleMonth.yearMonth, goToPrevious = { coroutineScope.launch { - state.animateScrollToMonth(state.firstVisibleMonth.yearMonth.previousMonth) + state.animateScrollToMonth(state.firstVisibleMonth.yearMonth.previous) } }, goToNext = { coroutineScope.launch { - state.animateScrollToMonth(state.firstVisibleMonth.yearMonth.nextMonth) + state.animateScrollToMonth(state.firstVisibleMonth.yearMonth.next) } }, ) diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/Example4Page.kt b/compose-multiplatform/sample/src/commonMain/kotlin/Example4Page.kt index 717f3d83..c57b5c97 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/Example4Page.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/Example4Page.kt @@ -34,7 +34,6 @@ import com.kizitonwose.calendar.core.DayPosition import com.kizitonwose.calendar.core.YearMonth import com.kizitonwose.calendar.core.firstDayOfWeekFromLocale import com.kizitonwose.calendar.core.now -import com.kizitonwose.calendar.core.plusMonths import org.jetbrains.compose.ui.tooling.preview.Preview @Composable diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/Example9Page.kt b/compose-multiplatform/sample/src/commonMain/kotlin/Example9Page.kt index 054321dd..8a36a605 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/Example9Page.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/Example9Page.kt @@ -55,11 +55,7 @@ import com.kizitonwose.calendar.core.YearMonth import com.kizitonwose.calendar.core.atEndOfMonth import com.kizitonwose.calendar.core.atStartOfMonth import com.kizitonwose.calendar.core.daysOfWeek -import com.kizitonwose.calendar.core.minusMonths -import com.kizitonwose.calendar.core.nextMonth import com.kizitonwose.calendar.core.now -import com.kizitonwose.calendar.core.plusMonths -import com.kizitonwose.calendar.core.previousMonth import com.kizitonwose.calendar.core.yearMonth import kotlinx.coroutines.launch import kotlinx.datetime.DayOfWeek @@ -224,7 +220,7 @@ object Example9PageSharedComponents { val targetDate = weekState.firstVisibleWeek.days.first().date.minusDays(1) weekState.animateScrollToWeek(targetDate) } else { - val targetMonth = monthState.firstVisibleMonth.yearMonth.previousMonth + val targetMonth = monthState.firstVisibleMonth.yearMonth.previous monthState.animateScrollToMonth(targetMonth) } } @@ -235,7 +231,7 @@ object Example9PageSharedComponents { val targetDate = weekState.firstVisibleWeek.days.last().date.plusDays(1) weekState.animateScrollToWeek(targetDate) } else { - val targetMonth = monthState.firstVisibleMonth.yearMonth.nextMonth + val targetMonth = monthState.firstVisibleMonth.yearMonth.next monthState.animateScrollToMonth(targetMonth) } } diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/Example9PageAnimatedVisibility.kt b/compose-multiplatform/sample/src/commonMain/kotlin/Example9PageAnimatedVisibility.kt index 16a36949..078b5b74 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/Example9PageAnimatedVisibility.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/Example9PageAnimatedVisibility.kt @@ -28,9 +28,7 @@ import com.kizitonwose.calendar.core.WeekDayPosition import com.kizitonwose.calendar.core.atEndOfMonth import com.kizitonwose.calendar.core.atStartOfMonth import com.kizitonwose.calendar.core.daysOfWeek -import com.kizitonwose.calendar.core.minusMonths import com.kizitonwose.calendar.core.now -import com.kizitonwose.calendar.core.plusMonths import com.kizitonwose.calendar.core.yearMonth import kotlinx.coroutines.launch import kotlinx.datetime.LocalDate diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/Flight.kt b/compose-multiplatform/sample/src/commonMain/kotlin/Flight.kt index ec603ea5..8e68fafe 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/Flight.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/Flight.kt @@ -1,9 +1,7 @@ import androidx.compose.ui.graphics.Color import com.kizitonwose.calendar.core.YearMonth import com.kizitonwose.calendar.core.atDay -import com.kizitonwose.calendar.core.minusMonths import com.kizitonwose.calendar.core.now -import com.kizitonwose.calendar.core.plusMonths import kotlinx.datetime.LocalDateTime import kotlinx.datetime.atTime import kotlinx.datetime.format.DayOfWeekNames diff --git a/compose-multiplatform/sample/src/commonMain/kotlin/Utils.kt b/compose-multiplatform/sample/src/commonMain/kotlin/Utils.kt index 42b37b43..45cc3c0b 100644 --- a/compose-multiplatform/sample/src/commonMain/kotlin/Utils.kt +++ b/compose-multiplatform/sample/src/commonMain/kotlin/Utils.kt @@ -27,6 +27,9 @@ import com.kizitonwose.calendar.compose.CalendarState import com.kizitonwose.calendar.compose.weekcalendar.WeekCalendarState import com.kizitonwose.calendar.core.CalendarMonth import com.kizitonwose.calendar.core.Week +import com.kizitonwose.calendar.core.YearMonth +import com.kizitonwose.calendar.core.minus +import com.kizitonwose.calendar.core.plus import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterNotNull import kotlinx.datetime.DateTimeUnit @@ -179,5 +182,10 @@ private fun CalendarLayoutInfo.firstMostVisibleMonth(viewportPercent: Float = 50 } internal fun LocalDate.plusDays(value: Int): LocalDate = plus(value, DateTimeUnit.DAY) - internal fun LocalDate.minusDays(value: Int): LocalDate = minus(value, DateTimeUnit.DAY) +internal fun YearMonth.plusMonths(value: Int): YearMonth = plus(value, DateTimeUnit.MONTH) +internal fun YearMonth.minusMonths(value: Int): YearMonth = minus(value, DateTimeUnit.MONTH) +internal val YearMonth.next: YearMonth + get() = this.minusMonths(1) +internal val YearMonth.previous: YearMonth + get() = this.minusMonths(1) diff --git a/compose/api/compose.api b/compose/api/compose.api index 336cfe9a..81615668 100644 --- a/compose/api/compose.api +++ b/compose/api/compose.api @@ -173,7 +173,6 @@ public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarSta } public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState$Companion { - public final fun getSaver ()Landroidx/compose/runtime/saveable/Saver; } public final class com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarStateKt { diff --git a/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt b/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt index 32bf2721..7cc76c4f 100644 --- a/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt +++ b/compose/src/main/java/com/kizitonwose/calendar/compose/weekcalendar/WeekCalendarState.kt @@ -261,7 +261,7 @@ public class WeekCalendarState internal constructor( } public companion object { - public val Saver: Saver = listSaver( + internal val Saver: Saver = listSaver( save = { listOf( it.startDate,