Skip to content

Respect system "First day of week" setting in week calculations - #2352

Merged
patrickunterwegs merged 5 commits into
developfrom
claude/first-day-of-week-settings-t4bzg7
Jul 26, 2026
Merged

Respect system "First day of week" setting in week calculations#2352
patrickunterwegs merged 5 commits into
developfrom
claude/first-day-of-week-settings-t4bzg7

Conversation

@patrickunterwegs

Copy link
Copy Markdown
Member

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

  • New utility function getLocalizedFirstDayOfWeek(): Uses LocalePreferences.getFirstDayOfWeek() to respect the system's "First day of week" setting (exposed via locale's -u-fw- unicode extension), with fallback to locale defaults
  • New utility function getLocalizedWeekFields(): Creates WeekFields that respect the localized first day of week while preserving the locale's minimal days in first week for proper week numbering
  • Updated isLocalizedWeekstartMonday(): Now delegates to getLocalizedFirstDayOfWeek() instead of directly using WeekFields.of()
  • Updated week number calculations: ICal4ListRel.kt now uses getLocalizedWeekFields() for week-of-year calculations in both start and due date displays
  • Updated week calendar UI: ListScreenWeek.kt now passes the localized first day of week to the week calendar component
  • Comprehensive test coverage: Added 4 new test cases covering German/US locales with and without system setting overrides, plus a @After teardown to restore the default locale

Implementation Details

  • Uses AndroidX's LocalePreferences.getFirstDayOfWeek() API which handles the unicode extension parsing
  • Maintains backward compatibility by falling back to WeekFields.of(Locale.getDefault()) for unknown/DEFAULT values
  • All week-related calculations now consistently respect user preferences across the app

https://claude.ai/code/session_01HyppcLmiTZZ4xMedBYoysx

claude added 2 commits July 23, 2026 10:46
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
@patrickunterwegs patrickunterwegs added this to the 2.17.1 milestone Jul 26, 2026
claude added 3 commits July 26, 2026 09:08
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
@patrickunterwegs
patrickunterwegs merged commit b29df00 into develop Jul 26, 2026
3 checks passed
@patrickunterwegs

Copy link
Copy Markdown
Member Author

Closes #2110

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants