From 77b0c6db09933109740ead9cee5291d833f72221 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 19:22:55 +0100 Subject: [PATCH] Week numbers follow the device region, shared helper (#493) --- .../calendula/ui/common/WeekNumber.kt | 21 +++++++++++++++++++ .../calendula/ui/month/MonthScreen.kt | 10 ++++----- .../calendula/ui/week/WeekScreen.kt | 6 ++---- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/de/jeanlucmakiola/calendula/ui/common/WeekNumber.kt diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/WeekNumber.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/WeekNumber.kt new file mode 100644 index 00000000..6b34b62c --- /dev/null +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/WeekNumber.kt @@ -0,0 +1,21 @@ +package de.jeanlucmakiola.calendula.ui.common + +import android.content.res.Resources +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import de.jeanlucmakiola.floret.time.rowWeekNumber +import kotlinx.datetime.LocalDate +import kotlinx.datetime.toJavaLocalDate +import java.time.temporal.WeekFields + +/** + * The week number of the grid row starting on [rowStart], numbered by the + * device region's rules (#493). The region, not the app language: an English + * UI in the Netherlands still numbers weeks the ISO way. Shared by the Month + * gutter and the Week badge so the two always agree. + */ +@Composable +internal fun rememberRowWeekNumber(rowStart: LocalDate): Int { + val fields = remember { WeekFields.of(Resources.getSystem().configuration.locales[0]) } + return remember(rowStart, fields) { rowStart.toJavaLocalDate().rowWeekNumber(fields) } +} diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt index a4dc9183..83001dfb 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt @@ -187,7 +187,6 @@ import de.jeanlucmakiola.floret.identity.itemEnter import de.jeanlucmakiola.floret.identity.rememberReduceMotion import de.jeanlucmakiola.floret.locale.currentLocale import de.jeanlucmakiola.calendula.ui.common.next -import de.jeanlucmakiola.floret.time.rowWeekNumber import kotlinx.coroutines.delay import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filterNotNull @@ -205,7 +204,7 @@ import java.time.format.TextStyle as JavaTextStyle import java.util.Locale import kotlinx.datetime.toJavaMonth import kotlinx.datetime.yearMonth -import java.time.temporal.WeekFields +import de.jeanlucmakiola.calendula.ui.common.rememberRowWeekNumber private val LocalTodayPulse = staticCompositionLocalOf { 0 } @@ -2703,13 +2702,12 @@ private fun monthChipDragModifier( * Left-gutter calendar-week cell (#25): a full-height tonal pill mirroring the * day cells' geometry, set apart by the secondaryContainer tint (matching the * Week view's badge), with the week number centred like a day number. It is - * numbered the locale's way from the row's mid-week day, as in the Week view, - * so it is right for any first weekday (#493). + * numbered by the device region from the row's mid-week day, as in the Week + * view, so it is right for any first weekday (#493). */ @Composable private fun WeekNumberGutter(weekStart: LocalDate, modifier: Modifier = Modifier) { - val locale = currentLocale() - val weekNumber = remember(weekStart, locale) { weekStart.toJavaLocalDate().rowWeekNumber(WeekFields.of(locale)) } + val weekNumber = rememberRowWeekNumber(weekStart) val label = stringResource(R.string.week_number_label) val openLabel = stringResource(R.string.month_open_week, weekNumber) val onOpenWeek = LocalOpenWeek.current diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt index 6a2cc629..f05c0fc8 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt @@ -209,7 +209,6 @@ import de.jeanlucmakiola.calendula.ui.common.TIMELINE_CONTENT_END_INSET import de.jeanlucmakiola.calendula.ui.common.hourCellBlockInset import de.jeanlucmakiola.calendula.ui.common.hourGridCells import de.jeanlucmakiola.calendula.ui.common.tappedMinuteOfDay -import de.jeanlucmakiola.floret.time.rowWeekNumber import kotlinx.coroutines.launch import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalDate @@ -221,7 +220,7 @@ import kotlinx.datetime.toLocalDateTime import java.time.format.TextStyle as JavaTextStyle import java.util.Locale import kotlinx.datetime.yearMonth -import java.time.temporal.WeekFields +import de.jeanlucmakiola.calendula.ui.common.rememberRowWeekNumber /** One lane of the all-day strip, sized to a trimmed bar line (#190). */ private val ALL_DAY_ROW_HEIGHT = 20.dp @@ -1138,8 +1137,7 @@ private fun WeekDayHeader( */ @Composable private fun WeekNumberCell(weekStart: LocalDate, showBadge: Boolean, modifier: Modifier = Modifier) { - val locale = currentLocale() - val weekNumber = remember(weekStart, locale) { weekStart.toJavaLocalDate().rowWeekNumber(WeekFields.of(locale)) } + val weekNumber = rememberRowWeekNumber(weekStart) Column( modifier = modifier .fillMaxWidth()