Respect system "First day of week" setting in week calculations - #2352
Merged
patrickunterwegs merged 5 commits intoJul 26, 2026
Conversation
The first day of the week was derived solely from the language/region locale via WeekFields.of(Locale.getDefault()).firstDayOfWeek. This ignored Android 13+'s "Regional preferences -> First day of week" system setting, so e.g. an en-US device with the setting set to Monday still showed Sunday as the first day. Use androidx LocalePreferences.getFirstDayOfWeek(), which reads that setting through the locale's "-u-fw-" unicode extension and falls back to the locale's default when unset. This is applied to the recurrence weekday order, the week calendar view, and week-number grouping. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HyppcLmiTZZ4xMedBYoysx
isLocalizedWeekstartMonday() was only used to order the recurrence weekday buttons, and it collapsed the first day of the week to a Monday/Sunday choice. Replace it with getLocalizedDaysOfWeek(), which returns the seven days ordered from the device's first day of the week, so any first day (e.g. Saturday) is honoured. The recur card maps this to ical4j WeekDay via a small reusable helper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HyppcLmiTZZ4xMedBYoysx
Material3's DatePicker and DateRangePicker derive their first day of the week from WeekFields.of(locale), which only considers the language/region of the locale and ignores the "Regional preferences -> First day of week" system setting (the locale's "-u-fw-" unicode extension). The composables expose no way to set the first day of the week directly, and the locale is baked into the picker state at rememberDatePickerState() time via the active LocalConfiguration. Add DateTimeUtils.getLocaleForLocalizedFirstDayOfWeek(), which returns a locale whose region makes WeekFields.of(...) resolve to the device's first day of the week (getLocalizedFirstDayOfWeek()) while keeping the language so month/weekday names are unchanged. Create the picker states under a CompositionLocalProvider that supplies this locale so the calendars start on the correct day. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HyppcLmiTZZ4xMedBYoysx
Material3 exposes an explicit `locale` parameter via the DatePickerState and DateRangePickerState factory functions. Use it to pass the first-day-of-week-aware locale directly, replacing the more verbose CompositionLocalProvider workaround. Note that the underlying library still derives the first day of the week from WeekFields.of(locale), so the region-adjusting getLocaleForLocalizedFirstDayOfWeek() is still required. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HyppcLmiTZZ4xMedBYoysx
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
Member
Author
|
Closes #2110 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for the Android 13+ system setting "Regional preferences → First day of week" in week-related calculations throughout the app. Previously, the app only considered the locale's default week start day and ignored user overrides.
Key Changes
getLocalizedFirstDayOfWeek(): UsesLocalePreferences.getFirstDayOfWeek()to respect the system's "First day of week" setting (exposed via locale's-u-fw-unicode extension), with fallback to locale defaultsgetLocalizedWeekFields(): CreatesWeekFieldsthat respect the localized first day of week while preserving the locale's minimal days in first week for proper week numberingisLocalizedWeekstartMonday(): Now delegates togetLocalizedFirstDayOfWeek()instead of directly usingWeekFields.of()ICal4ListRel.ktnow usesgetLocalizedWeekFields()for week-of-year calculations in both start and due date displaysListScreenWeek.ktnow passes the localized first day of week to the week calendar component@Afterteardown to restore the default localeImplementation Details
LocalePreferences.getFirstDayOfWeek()API which handles the unicode extension parsingWeekFields.of(Locale.getDefault())for unknown/DEFAULT valueshttps://claude.ai/code/session_01HyppcLmiTZZ4xMedBYoysx