Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeekFields.getFirstDayOfWeek() does not respect Android 14 regional preferences settings #186

Open
equeim opened this issue Oct 5, 2023 · 1 comment

Comments

@equeim
Copy link

equeim commented Oct 5, 2023

When first day of week is changed in Android 14 settings (https://developer.android.com/about/versions/14/features#regional-preferences), value of WeekFields.of(Locale.getDefault()).getFirstDayOfWeek() does not match that of Calendar.getInstance().getFirstDayOfWeek() or java.time.temporal.WeekFields.of(Locale.getDefault()).getFirstDayOfWeek():

This what various APIs return when default first day of week is monday, and it's changed to sunday in system settings:

first day of week org.threeten.bp.temporal = MONDAY
first day of week java.time.temporal.WeekFields = SUNDAY
first day of week java.util.Calendar = 1
first day of week androidx.core.text.utilLocalePreferences = sun

As you can see only threetenbp returns incorrect value.

@sschaap
Copy link
Contributor

sschaap commented Feb 16, 2024

It looks like Android uses the BCP 47 'U' extension to override the first day of week in the locale specifier. For example, configuring Wednesday as the first day of week in the Android regional settings in an otherwise en-us environment yields a en_US_#u-fw-wed locale specifier.

When such a locale is used with WeekFields.of(Locale) the u-fw-wed extension is removed before WeekFields resolves the first-day-of-week through the java.util.Calendar API. I'm not sure why this happens. Perhaps @jodastephen can shed some light on why the 'eliminate variants' step is present?

If the variant elimination is removed and the original locale object is passed to Calendar.getInstance(), the correct fdow is used by WeekFields.

BCP 47 'U' extension: https://cldr.unicode.org/index/bcp47-extension

BCP 47 'U' - First day of week: https://github.com/unicode-org/cldr/blob/d1c59aeea6a26cd1018e164e8c470e4873925cac/common/bcp47/calendar.xml#L34

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

No branches or pull requests

2 participants