8257964: Broken Calendar#getMinimalDaysInFirstWeek with java.locale.providers=HOST

Reviewed-by: joehw
This commit is contained in:
Naoto Sato 2020-12-11 21:26:16 +00:00
parent f9c9bf03a8
commit 74b79c6e19
4 changed files with 54 additions and 3 deletions

View file

@ -75,7 +75,7 @@ public class HostLocaleProviderAdapterImpl {
// CalendarData value types
private static final int CD_FIRSTDAYOFWEEK = 0;
private static final int CD_MINIMALDAYSINFIRSTWEEK = 1;
private static final int CD_FIRSTWEEKOFYEAR = 1;
// Currency/Locale display name types
private static final int DN_CURRENCY_NAME = 0;
@ -366,7 +366,15 @@ public class HostLocaleProviderAdapterImpl {
@Override
public int getMinimalDaysInFirstWeek(Locale locale) {
return 0;
int firstWeek = getCalendarDataValue(
removeExtensions(locale).toLanguageTag(),
CD_FIRSTWEEKOFYEAR);
// Interpret the value from Windows LOCALE_IFIRSTWEEKOFYEAR setting
return switch (firstWeek) {
case 1 -> 7; // First full week following 1/1 is the first week of the year.
case 2 -> 4; // First week containing at least four days is the first week of the year.
default -> 1; // First week can be a single day, if 1/1 falls on the last day of the week.
};
}
};
}

View file

@ -647,6 +647,11 @@ JNIEXPORT jint JNICALL Java_sun_util_locale_provider_HostLocaleProviderAdapterIm
LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
(LPWSTR)&num, sizeof(num));
break;
case sun_util_locale_provider_HostLocaleProviderAdapterImpl_CD_FIRSTWEEKOFYEAR:
got = getLocaleInfoWrapper(langtag,
LOCALE_IFIRSTWEEKOFYEAR | LOCALE_RETURN_NUMBER,
(LPWSTR)&num, sizeof(num));
break;
}
(*env)->ReleaseStringChars(env, jlangtag, langtag);