From 5293b8fe28d6f7ab59364febfbb7ab718572ffaf Mon Sep 17 00:00:00 2001 From: Shivam Goyal Date: Tue, 1 Jul 2025 14:31:10 +0530 Subject: [PATCH] NTP-7561 | Upgrade kotlinx-datetime & kotlinx-serialization (#16787) --- android/gradle/libs.versions.toml | 4 ++-- .../billcalendar/domain/model/data/MonthYear.kt | 6 ++++-- .../domain/model/response/BillCalendarResponse.kt | 3 ++- .../domain/usecase/BillCalendarGridUseCase.kt | 6 ++++-- .../presentation/ui/calendar/EmptyDayCell.kt | 2 +- .../presentation/ui/calendar/MultiBillDayCell.kt | 2 +- .../billcalendar/presentation/ui/details/DateHeading.kt | 2 +- .../utils/extensions/BillCalendarExtensions.kt | 3 ++- .../presentation/utils/util/BillCalendarUtil.kt | 9 ++++++--- 9 files changed, 23 insertions(+), 14 deletions(-) diff --git a/android/gradle/libs.versions.toml b/android/gradle/libs.versions.toml index daa73b45ff..3338c990a4 100644 --- a/android/gradle/libs.versions.toml +++ b/android/gradle/libs.versions.toml @@ -87,8 +87,8 @@ juspay-hypersdk = "2.1.33" juspay-hypersdkPlugin = "2.0.4" kotlin = "2.2.0" kotlinx-coroutines = "1.10.2" -kotlinx-serialization = "1.8.1" -kotlinx-datetime = "0.6.0" +kotlinx-serialization = "1.9.0" +kotlinx-datetime = "0.7.0" ksp = "2.2.0-2.0.2" lottie = "6.6.7" masayukiSuda-easingInterpolator = "v1.3.2" diff --git a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/model/data/MonthYear.kt b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/model/data/MonthYear.kt index 81e91607b9..c36806491d 100644 --- a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/model/data/MonthYear.kt +++ b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/model/data/MonthYear.kt @@ -9,17 +9,19 @@ package com.navi.moneymanager.billcalendar.domain.model.data import androidx.compose.runtime.Immutable import com.navi.moneymanager.common.model.Month -import kotlinx.datetime.Clock +import kotlin.time.Clock import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone +import kotlinx.datetime.number import kotlinx.datetime.toLocalDateTime @Immutable data class MonthYear(val month: Int, val year: Int) { companion object { + @OptIn(kotlin.time.ExperimentalTime::class) fun current(): MonthYear { val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date - return MonthYear(now.monthNumber, now.year) + return MonthYear(now.month.number, now.year) } } diff --git a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/model/response/BillCalendarResponse.kt b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/model/response/BillCalendarResponse.kt index 0f92ade26f..d214a49dba 100644 --- a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/model/response/BillCalendarResponse.kt +++ b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/model/response/BillCalendarResponse.kt @@ -15,7 +15,7 @@ import com.navi.moneymanager.billcalendar.presentation.model.data.BillCalendarIc import com.navi.moneymanager.billcalendar.presentation.utils.util.timestampToLocalDateInIST import com.navi.moneymanager.common.utils.Constants.RUPEE_SYMBOL import com.navi.naviwidgets.utils.formatAmount -import kotlinx.datetime.Clock +import kotlin.time.Clock import kotlinx.datetime.TimeZone import kotlinx.datetime.daysUntil import kotlinx.datetime.toLocalDateTime @@ -49,6 +49,7 @@ data class BillData( } } + @OptIn(kotlin.time.ExperimentalTime::class) fun calculateDaysUntilBillDue(): Int { val dueDate = timestampToLocalDateInIST(billDueDate) val today = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date diff --git a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/usecase/BillCalendarGridUseCase.kt b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/usecase/BillCalendarGridUseCase.kt index d18345bea5..51997a1905 100644 --- a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/usecase/BillCalendarGridUseCase.kt +++ b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/domain/usecase/BillCalendarGridUseCase.kt @@ -17,12 +17,13 @@ import com.navi.moneymanager.billcalendar.presentation.utils.util.timestampToLoc import com.navi.moneymanager.common.dataprovider.data.dashboard.helper.MMConfigResponseHelper import javax.inject.Inject import kotlin.math.abs -import kotlinx.datetime.Clock +import kotlin.time.Clock import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone import kotlinx.datetime.isoDayNumber import kotlinx.datetime.minus +import kotlinx.datetime.number import kotlinx.datetime.plus import kotlinx.datetime.toLocalDateTime @@ -43,6 +44,7 @@ constructor(private val mmConfigHelper: MMConfigResponseHelper) { return calendarGrid } + @OptIn(kotlin.time.ExperimentalTime::class) private fun constructGrid(monthYear: MonthYear, bills: List): List { val monthlyBills = mutableListOf() val today = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date @@ -53,7 +55,7 @@ constructor(private val mmConfigHelper: MMConfigResponseHelper) { while (currentDate <= calendarEndDate) { val isEnabled = - currentDate.monthNumber == monthYear.month && currentDate.year == monthYear.year + currentDate.month.number == monthYear.month && currentDate.year == monthYear.year val isToday = currentDate == today val billList = if (isEnabled) { diff --git a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/calendar/EmptyDayCell.kt b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/calendar/EmptyDayCell.kt index bb3c02819f..20b514f588 100644 --- a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/calendar/EmptyDayCell.kt +++ b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/calendar/EmptyDayCell.kt @@ -55,7 +55,7 @@ fun EmptyDayCell( contentAlignment = Alignment.Center, ) { ElexText( - text = date.dayOfMonth.toString(), + text = date.day.toString(), color = textColor, fontSize = 14.sp, fontWeight = fontWeight, diff --git a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/calendar/MultiBillDayCell.kt b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/calendar/MultiBillDayCell.kt index 43f11a1bb5..3ff69bd771 100644 --- a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/calendar/MultiBillDayCell.kt +++ b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/calendar/MultiBillDayCell.kt @@ -37,7 +37,7 @@ fun MultiBillDayCell( Box(modifier = modifier) { CellBackground(isToday = isToday, onClick = onClick) { ElexText( - text = date.dayOfMonth.toString(), + text = date.day.toString(), color = elexColors.base.text.gray.subtle, fontSize = 14.sp, fontWeight = FontWeightEnum.NAVI_BODY_DEMI_BOLD, diff --git a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/details/DateHeading.kt b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/details/DateHeading.kt index ebd9f3ea57..d707e79051 100644 --- a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/details/DateHeading.kt +++ b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/ui/details/DateHeading.kt @@ -79,7 +79,7 @@ fun DateHeading( buildString { append(date.month.name.lowercase().replaceFirstChar { it.uppercaseChar() }) append(SPACE) - append(date.dayOfMonth) + append(date.day) } } diff --git a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/utils/extensions/BillCalendarExtensions.kt b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/utils/extensions/BillCalendarExtensions.kt index 597c0be1a6..bdd8c420f6 100644 --- a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/utils/extensions/BillCalendarExtensions.kt +++ b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/utils/extensions/BillCalendarExtensions.kt @@ -25,6 +25,7 @@ import com.navi.moneymanager.common.illustration.repository.ImageRepository.Comp import com.navi.moneymanager.common.model.Month import com.navi.moneymanager.common.utils.MonthConstants.monthNames import kotlinx.datetime.LocalDate +import kotlinx.datetime.number fun MonthYear.toMonthString(): String = buildString { append(Month.fromInt(this@toMonthString.month).fullName) @@ -111,5 +112,5 @@ fun MonthYear.toFormattedMonthYear(): String { } fun LocalDate.toMonthYear(): MonthYear { - return MonthYear(monthNumber, year) + return MonthYear(month.number, year) } diff --git a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/utils/util/BillCalendarUtil.kt b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/utils/util/BillCalendarUtil.kt index 0118d47da0..094d508ff6 100644 --- a/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/utils/util/BillCalendarUtil.kt +++ b/android/navi-money-manager/src/main/kotlin/com/navi/moneymanager/billcalendar/presentation/utils/util/BillCalendarUtil.kt @@ -21,8 +21,8 @@ import com.navi.moneymanager.R import com.navi.moneymanager.billcalendar.domain.model.data.MonthYear import com.navi.moneymanager.billcalendar.presentation.utils.constants.BillCalendarConstants import com.navi.moneymanager.billcalendar.presentation.utils.extensions.toMonthYear -import kotlinx.datetime.Clock -import kotlinx.datetime.Instant +import kotlin.time.Clock +import kotlin.time.Instant import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone import kotlinx.datetime.daysUntil @@ -32,6 +32,7 @@ fun toJson(data: T, gsonDeserializer: Gson): String { return gsonDeserializer.toJson(data) } +@OptIn(kotlin.time.ExperimentalTime::class) fun getDueDateText(date: LocalDate, context: Context): String { val currentDate = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date val numberOfDays = currentDate.daysUntil(date) @@ -43,6 +44,7 @@ fun getDueDateText(date: LocalDate, context: Context): String { } } +@OptIn(kotlin.time.ExperimentalTime::class) @Composable fun getDueDateColor(date: LocalDate): Color { val currentDate = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date @@ -59,7 +61,7 @@ fun getMonthPrefix(date: LocalDate): String { } fun formatDateIntoPrefixMonthNames(date: LocalDate): String { - val day = date.dayOfMonth + val day = date.day val suffix = getDateSuffix(day) val month = getMonthPrefix(date) return buildString { @@ -70,6 +72,7 @@ fun formatDateIntoPrefixMonthNames(date: LocalDate): String { } } +@OptIn(kotlin.time.ExperimentalTime::class) fun timestampToLocalDateInIST(timestamp: String?): LocalDate { if (timestamp.isNullOrEmpty()) { return LocalDate(1970, 1, 1)