public class ForceIsoWeekNumber
extends java.util.spi.CalendarDataProvider
As of Java 23, the COMPAT locale provider was removed https://bugs.openjdk.org/browse/JDK-8325568 . This provider could be used by specifying -Djava.locale.providers=COMPAT,... at startup, to fix the week number rules which, while formerly correct, starting with JRE9 by using the CLDR data from the Unicode Consortium, were objectively wrong (which means equal to the US's rules).
Not using the COMPAT provider would result in having wrong week numbers in SimpleDateFormat and DateTimeFormat, as they use the 'local' definition instead of the ISO definition, which just counts Thursdays: https://en.wikipedia.org/wiki/ISO_week_date
Although the java.time code knows about the ISO rules, using the formatters will always pick the wrong definition, ignoring users relying on the formatters.
This CalendarDataProvider will force ISO week number rule for any locale known by the current JVM.
This is unnecessarily complicated and intrusive; as the official way, where we have to give a list of supported Locales before the JVM has this list available for us. This provider works by checking files within /modules/jdk.localedata/sun/text/resources/cldr to accomplish that task without using static lists. This class needs two additional things to do it's work:
| Constructor and Description |
|---|
ForceIsoWeekNumber()
no args constructor as needed by SPI
|
| Modifier and Type | Method and Description |
|---|---|
java.util.Locale[] |
getAvailableLocales()
This method will be called by the JVM so early, that the call to Locale::getAvailableLocales
will result in an NPE caused the the not yet instantiated internal pool.
|
int |
getFirstDayOfWeek(java.util.Locale l)
Return the first day of the week according to CLDR data, which we extracted during
|
int |
getMinimalDaysInFirstWeek(java.util.Locale l)
Return the the minimal days in the first week, which, if we translate that
to the ISO rule, just means how many days from week start until thursday.
|
boolean |
isSupportedLocale(java.util.Locale l)
Returns true as it will only be asked for Locales returned in getAvailableLocales,
which we supplied already in the first place.
|
public ForceIsoWeekNumber()
public java.util.Locale[] getAvailableLocales()
getAvailableLocales in class java.util.spi.LocaleServiceProviderpublic boolean isSupportedLocale(java.util.Locale l)
isSupportedLocale in class java.util.spi.LocaleServiceProviderl - the locale to check forpublic int getFirstDayOfWeek(java.util.Locale l)
getFirstDayOfWeek in class java.util.spi.CalendarDataProviderl - the locale to get the first day of the week for.public int getMinimalDaysInFirstWeek(java.util.Locale l)
getMinimalDaysInFirstWeek in class java.util.spi.CalendarDataProviderl - the locale to get the minimal days in first week forCopyright © 2000-2026 OAshi S.à r.l. All Rights Reserved.