diff --git a/core/src/main/kotlin/plus/rua/project/CalendarViewModel.kt b/core/src/main/kotlin/plus/rua/project/CalendarViewModel.kt index 50aa9ae..ca91e4a 100644 --- a/core/src/main/kotlin/plus/rua/project/CalendarViewModel.kt +++ b/core/src/main/kotlin/plus/rua/project/CalendarViewModel.kt @@ -12,6 +12,7 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.stateIn import kotlinx.datetime.DatePeriod import kotlinx.datetime.LocalDate +import kotlinx.datetime.Month import kotlinx.datetime.TimeZone import kotlinx.datetime.daysUntil import kotlinx.datetime.minus @@ -100,8 +101,6 @@ class CalendarViewModel( // 预计算当前月前后各 1 个月(在协程中异步执行) val currentYear = today.year val currentMonth = today.month.number - - @Suppress("DEPRECATION") // monthNumber 无替代 API val monthsToPrecompute = listOf( currentMonth - 1 to currentYear, currentMonth to currentYear, @@ -135,7 +134,6 @@ class CalendarViewModel( private val _collapseProgress = MutableStateFlow(0f) val collapseProgress: StateFlow = _collapseProgress.asStateFlow() - @Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 val currentMonth: Int get() = selectedDate.value.month.number val currentYear: Int get() = selectedDate.value.year @@ -244,13 +242,12 @@ class CalendarViewModel( /** * 从年视图选择月份后返回月视图。 */ - @Suppress("DEPRECATION") // monthNumber 无替代 API fun selectMonthFromYearView(month: Int) { val t0 = System.nanoTime() logd(TAG_VM, "[selectMonthFromYearView] ===== START month=$month t=$t0 =====") composeTraceBeginSection("YearView:SelectMonth") val date = if (_yearViewYear.value == today.year && today.month.number == month) today - else LocalDate(_yearViewYear.value, month, 1) + else LocalDate(_yearViewYear.value, Month(month), 1) logd(TAG_VM, "[selectMonthFromYearView] targetDate=$date dt=${(System.nanoTime() - t0) / 1_000_000}ms") _selectedDate.value = date logd(TAG_VM, "[selectMonthFromYearView] selectedDate set dt=${(System.nanoTime() - t0) / 1_000_000}ms") @@ -376,7 +373,6 @@ class CalendarViewModel( * @param month 月份(1-12) * @return 日历网格列表,每项包含日期、是否当月、是否今天、是否选中 */ - @Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 fun getMonthDays(year: Int, month: Int): List { composeTraceBeginSection("getMonthDays:$year-$month") val info = getMonthGridInfo(year, month) diff --git a/core/src/main/kotlin/plus/rua/project/LunarCache.kt b/core/src/main/kotlin/plus/rua/project/LunarCache.kt index 5c1a6c9..3199e23 100644 --- a/core/src/main/kotlin/plus/rua/project/LunarCache.kt +++ b/core/src/main/kotlin/plus/rua/project/LunarCache.kt @@ -4,6 +4,7 @@ import com.tyme.solar.SolarDay import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.datetime.LocalDate +import kotlinx.datetime.number /** * 农历/节气/节假日信息缓存。 @@ -18,13 +19,11 @@ class LunarCache( ) { private val mutex = Mutex() - @Suppress("DEPRECATION") private val cache = LinkedHashMap(256, 0.75f, true) /** * 获取指定日期的信息,缓存 miss 时计算。 */ - @Suppress("DEPRECATION") // monthNumber 无替代 API suspend fun getOrCompute(date: LocalDate): DayCellInfo = mutex.withLock { cache[date]?.let { return@withLock it } val computed = compute(date) @@ -52,7 +51,6 @@ class LunarCache( * * 复用缓存中的 lunarMonthName 和 annotationText,避免重复创建 SolarDay。 */ - @Suppress("DEPRECATION") // monthNumber 无替代 API suspend fun formatLunarDate(date: LocalDate): String { val info = getOrCompute(date) val dayText = info.annotationText.removeSuffix("月") @@ -71,9 +69,8 @@ class LunarCache( } } - @Suppress("DEPRECATION") // monthNumber 无替代 API private fun compute(date: LocalDate): DayCellInfo { - val solarDay = SolarDay.fromYmd(date.year, date.monthNumber, date.day) + val solarDay = SolarDay.fromYmd(date.year, date.month.number, date.day) val holidayBadge = solarDay.getLegalHoliday()?.let { if (it.isWork()) "班" else "休" } val lunarDay = solarDay.getLunarDay() val lunarMonth = lunarDay.getLunarMonth() diff --git a/core/src/main/kotlin/plus/rua/project/ui/BottomCard.kt b/core/src/main/kotlin/plus/rua/project/ui/BottomCard.kt index 426348e..75e5d0a 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/BottomCard.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/BottomCard.kt @@ -31,6 +31,7 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import kotlinx.datetime.LocalDate +import kotlinx.datetime.number import plus.rua.project.LunarCache import plus.rua.project.ShiftKind @@ -68,8 +69,7 @@ fun BottomCard( ) { val relativeDesc = relativeDayDescription(selectedDate, today) - @Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 - val solarDesc = "${selectedDate.monthNumber}月${selectedDate.day}日" + val solarDesc = "${selectedDate.month.number}月${selectedDate.day}日" val lunarDesc by produceState( initialValue = "", key1 = selectedDate diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt index edb8edc..497093b 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthPage.kt @@ -26,6 +26,7 @@ import plus.rua.project.composeTraceEndSection import plus.rua.project.util.logd import kotlinx.datetime.DatePeriod import kotlinx.datetime.LocalDate +import kotlinx.datetime.Month import kotlinx.datetime.minus import kotlinx.datetime.number import kotlinx.datetime.plus @@ -290,12 +291,11 @@ data class HolidayEdgeInfo( val isEnd: Boolean ) -@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 private fun generateMonthDays(year: Int, month: Int): List { - val firstOfMonth = LocalDate(year, month, 1) + val firstOfMonth = LocalDate(year, Month(month), 1) val offset = firstOfMonth.dayOfWeek.ordinal val startDate = firstOfMonth.minus(DatePeriod(days = offset)) - val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1) + val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, Month(month + 1), 1) val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).day val rows = ((offset + daysInMonth - 1) / 7) + 1 val totalDays = rows * 7 diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt index b74aab9..54bcd6b 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarMonthView.kt @@ -72,6 +72,7 @@ import androidx.compose.ui.unit.dp import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.datetime.LocalDate +import kotlinx.datetime.Month import kotlinx.datetime.TimeZone import kotlinx.datetime.number import kotlinx.datetime.plus @@ -105,7 +106,6 @@ fun CalendarMonthView( val uiState by viewModel.uiState.collectAsState() val selectedDate = uiState.selectedDate val currentYear = selectedDate.year - @Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 val currentMonth = selectedDate.month.number val isCollapsed = uiState.isCollapsed val isYearView = uiState.isYearView @@ -162,7 +162,6 @@ fun CalendarMonthView( // 折叠态 WeekPager 切月时,持续同步 CalendarPager 的 pagerState LaunchedEffect(selectedDate) { - @Suppress("DEPRECATION") // monthNumber 无替代 API val targetPage = yearMonthToPage( selectedDate.year, selectedDate.month.number, today.year, today.month.number @@ -248,9 +247,8 @@ fun CalendarMonthView( } val onMonthChanged = remember(viewModel, today) { { year: Int, month: Int -> - @Suppress("DEPRECATION") val date = if (year == today.year && today.month.number == month) today - else LocalDate(year, month, 1) + else LocalDate(year, Month(month), 1) viewModel.selectDate(date) } } @@ -342,7 +340,6 @@ fun CalendarMonthView( val clickT = System.nanoTime() logd("AnimLog") { "[YearGridView] MonthClick month=$month year=$pageYear t=$clickT" } viewModel.selectMonthFromYearView(month) - @Suppress("DEPRECATION") // monthNumber 无替代 API val targetPage = yearMonthToPage( yearViewYear, month, today.year, today.month.number diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarPager.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarPager.kt index d9cd2c8..f5aa90e 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarPager.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarPager.kt @@ -62,8 +62,6 @@ fun CalendarPager( modifier: Modifier = Modifier ) { val initialYear = remember { today.year } - - @Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 val initialMonth = remember { today.month.number } val coroutineScope = rememberCoroutineScope() @@ -118,8 +116,6 @@ fun CalendarPager( onDateClick(date) // 点击跨月日期时,滚动到该月对应的页 val clickedYear = date.year - - @Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 val clickedMonth = date.month.number if (clickedYear != year || clickedMonth != month) { val targetPage = diff --git a/core/src/main/kotlin/plus/rua/project/ui/CalendarUtils.kt b/core/src/main/kotlin/plus/rua/project/ui/CalendarUtils.kt index 421d94a..e616160 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/CalendarUtils.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/CalendarUtils.kt @@ -3,6 +3,7 @@ package plus.rua.project.ui import com.tyme.solar.SolarDay import kotlinx.datetime.DatePeriod import kotlinx.datetime.LocalDate +import kotlinx.datetime.Month import kotlinx.datetime.daysUntil import kotlinx.datetime.minus import kotlinx.datetime.number @@ -60,10 +61,10 @@ data class MonthGridInfo( * @return 月份网格信息 */ fun getMonthGridInfo(year: Int, month: Int): MonthGridInfo { - val firstOfMonth = LocalDate(year, month, 1) + val firstOfMonth = LocalDate(year, Month(month), 1) val offset = firstOfMonth.dayOfWeek.ordinal val startDate = firstOfMonth.minus(DatePeriod(days = offset)) - val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1) + val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, Month(month + 1), 1) val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).day val rows = ((offset + daysInMonth - 1) / 7) + 1 val totalDays = rows * 7 @@ -90,8 +91,6 @@ fun calculateWeeksCount(year: Int, month: Int): Int { */ fun calculateWeeksCountForPage(page: Int, today: LocalDate): Int { val initialYear = today.year - - @Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 val initialMonth = today.month.number val offset = page - START_PAGE val totalMonths = initialYear * 12 + (initialMonth - 1) + offset @@ -190,9 +189,8 @@ fun relativeDayDescription(selectedDate: LocalDate, today: LocalDate): String { * @param date 公历日期 * @return 农历日期描述 */ -@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口 fun formatLunarDate(date: LocalDate): String { - val solarDay = SolarDay.fromYmd(date.year, date.monthNumber, date.day) + val solarDay = SolarDay.fromYmd(date.year, date.month.number, date.day) val lunarDay = solarDay.getLunarDay() val lunarMonth = lunarDay.getLunarMonth() return "农历${lunarMonth.getName()}${lunarDay.getName()}" diff --git a/core/src/main/kotlin/plus/rua/project/ui/DateCheckerScreen.kt b/core/src/main/kotlin/plus/rua/project/ui/DateCheckerScreen.kt index 3901072..4dfa7ae 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/DateCheckerScreen.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/DateCheckerScreen.kt @@ -74,6 +74,7 @@ import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone import kotlinx.datetime.atStartOfDayIn import kotlinx.datetime.daysUntil +import kotlinx.datetime.number import kotlinx.datetime.plus import kotlinx.datetime.toLocalDateTime import kotlinx.datetime.todayIn @@ -689,13 +690,12 @@ private fun LocalDate.toEpochMillis(): Long = private fun Long.toLocalDate(): LocalDate = Instant.fromEpochMilliseconds(this).toLocalDateTime(TimeZone.UTC).date -@Suppress("DEPRECATION") // monthNumber/dayOfMonth 无替代 API,kotlinx-datetime 尚未提供新接口 private fun LocalDate.formatChinese(): String = - "${year}年${monthNumber}月${dayOfMonth}日" + "${year}年${month.number}月${day}日" -@Suppress("DEPRECATION", "Unused") // monthNumber/dayOfMonth 无替代 API +@Suppress("Unused") private fun LocalDate.formatShortChinese(): String = - "${monthNumber}月${dayOfMonth}日" + "${month.number}月${day}日" private fun LocalDate.dayOfWeekChinese(): String = when (dayOfWeek.ordinal) { 0 -> "周一" diff --git a/core/src/main/kotlin/plus/rua/project/ui/DayCell.kt b/core/src/main/kotlin/plus/rua/project/ui/DayCell.kt index 905eea8..c11ca24 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/DayCell.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/DayCell.kt @@ -40,6 +40,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.zIndex import kotlinx.datetime.LocalDate +import kotlinx.datetime.number import plus.rua.project.DayCellInfo import plus.rua.project.LunarCache import plus.rua.project.ShiftKind @@ -265,11 +266,10 @@ private fun DayCellImpl( modifier = Modifier .fillMaxSize() .semantics { - @Suppress("DEPRECATION") contentDescription = if (isToday) { - "今天 ${date.year}年${date.monthNumber}月${date.day}日" + "今天 ${date.year}年${date.month.number}月${date.day}日" } else { - "${date.year}年${date.monthNumber}月${date.day}日" + "${date.year}年${date.month.number}月${date.day}日" } } .clip(CircleShape) diff --git a/core/src/main/kotlin/plus/rua/project/ui/YearGridView.kt b/core/src/main/kotlin/plus/rua/project/ui/YearGridView.kt index 8a25676..5082ff2 100644 --- a/core/src/main/kotlin/plus/rua/project/ui/YearGridView.kt +++ b/core/src/main/kotlin/plus/rua/project/ui/YearGridView.kt @@ -46,6 +46,7 @@ import androidx.compose.ui.semantics.semantics import com.tyme.lunar.LunarYear import kotlinx.datetime.DatePeriod import kotlinx.datetime.LocalDate +import kotlinx.datetime.Month import kotlinx.datetime.minus import kotlinx.datetime.number import kotlinx.datetime.plus @@ -304,13 +305,12 @@ private data class MiniDayData( val isCurrentMonth: Boolean ) -@Suppress("DEPRECATION") // monthNumber 无替代 API private fun generateMiniMonthDays(year: Int, month: Int): List { composeTraceBeginSection("generateMiniMonthDays:$year-$month") - val firstOfMonth = LocalDate(year, month, 1) + val firstOfMonth = LocalDate(year, Month(month), 1) val offset = firstOfMonth.dayOfWeek.ordinal val startDate = firstOfMonth.minus(DatePeriod(days = offset)) - val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1) + val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, Month(month + 1), 1) val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).day val rows = ((offset + daysInMonth - 1) / 7) + 1 val totalDays = rows * 7 diff --git a/core/src/test/kotlin/plus/rua/project/CalendarViewModelTest.kt b/core/src/test/kotlin/plus/rua/project/CalendarViewModelTest.kt index e82e525..065b97c 100644 --- a/core/src/test/kotlin/plus/rua/project/CalendarViewModelTest.kt +++ b/core/src/test/kotlin/plus/rua/project/CalendarViewModelTest.kt @@ -3,6 +3,7 @@ package plus.rua.project import kotlinx.datetime.Clock import kotlinx.datetime.Instant import kotlinx.datetime.LocalDate +import kotlinx.datetime.number import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse @@ -73,8 +74,7 @@ class CalendarViewModelTest { val vm = createViewModel() val days = vm.getMonthDays(2026, 5) assertFalse(days[0].isCurrentMonth) - @Suppress("DEPRECATION") // monthNumber — needed for Int comparison - assertEquals(4, days[0].date.monthNumber) + assertEquals(4, days[0].date.month.number) assertEquals(27, days[0].date.day) } @@ -84,8 +84,7 @@ class CalendarViewModelTest { val days = vm.getMonthDays(2026, 5) assertTrue(days[4].isCurrentMonth) assertEquals(1, days[4].date.day) - @Suppress("DEPRECATION") // monthNumber — needed for Int comparison - assertEquals(5, days[4].date.monthNumber) + assertEquals(5, days[4].date.month.number) } @Test