Skip to content

Commit e35b1bf

Browse files
committed
Document DatePicker first-day-of-week limitation
Material3's DatePicker derives its first day of the week from WeekFields.of(locale), which can only ever yield a day that some region uses (Monday, Friday, Saturday or Sunday). Tuesday/Wednesday/Thursday cannot be represented, so the workaround falls back to the locale default for those. Make this explicit in the documentation so it is not mistaken for a bug. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HyppcLmiTZZ4xMedBYoysx
1 parent 88ac8cf commit e35b1bf

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

app/src/main/java/at/techbee/jtx/util/DateTimeUtils.kt

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,23 @@ object DateTimeUtils {
230230
)
231231

232232
/**
233-
* Material3's DatePicker/DateRangePicker derive their first day of the week from
234-
* WeekFields.of(locale), which only looks at the language/region of the locale and ignores the
235-
* "Regional preferences -> First day of week" system setting (the locale's "-u-fw-" unicode
236-
* extension). As those composables offer no way to set the first day of the week directly, this
237-
* returns a locale, based on [baseLocale], whose region makes WeekFields.of(...) resolve to
238-
* [getLocalizedFirstDayOfWeek]. Only the region is changed, so the language (and therefore the
239-
* month/weekday names) of [baseLocale] is preserved.
233+
* Material3's DatePicker/DateRangePicker derive their first day of the week solely from
234+
* `WeekFields.of(locale).firstDayOfWeek`, which only looks at the language/region of the locale
235+
* and ignores the "Regional preferences -> First day of week" system setting (the locale's
236+
* "-u-fw-" unicode extension). As those composables offer no way to set the first day of the
237+
* week directly, this returns a locale, based on [baseLocale], whose region makes
238+
* WeekFields.of(...) resolve to [getLocalizedFirstDayOfWeek]. Only the region is changed, so the
239+
* language (and therefore the month/weekday names) of [baseLocale] is preserved.
240+
*
241+
* Limitation: `WeekFields.of(...)` can only ever yield a first day of the week that some region
242+
* actually uses, and worldwide that is only Monday, Friday, Saturday or Sunday. If the user
243+
* picks Tuesday, Wednesday or Thursday (Android allows any day), Material3's picker cannot
244+
* represent it, so this falls back to [baseLocale] and the picker keeps the locale's default
245+
* first day. Components that render the week themselves (see [getLocalizedDaysOfWeek]) are not
246+
* affected by this and honour any first day.
240247
*
241248
* @return the adjusted locale, or [baseLocale] unchanged if it already starts the week on the
242-
* desired day, or if that day cannot be represented by a region (WeekFields only knows Monday,
243-
* Friday, Saturday and Sunday as first days of the week).
249+
* desired day, or if that day cannot be represented by a region (see the limitation above).
244250
*/
245251
fun getLocaleForLocalizedFirstDayOfWeek(baseLocale: Locale = Locale.getDefault()): Locale {
246252
val firstDayOfWeek = getLocalizedFirstDayOfWeek()
@@ -252,7 +258,7 @@ object DateTimeUtils {
252258
DayOfWeek.FRIDAY -> "MV"
253259
DayOfWeek.SATURDAY -> "SA"
254260
DayOfWeek.SUNDAY -> "US"
255-
else -> return baseLocale
261+
else -> return baseLocale // Tue/Wed/Thu: no region uses these, Material3 can't show them
256262
}
257263
return Locale.Builder().setLocale(baseLocale).setRegion(region).build()
258264
}

0 commit comments

Comments
 (0)