Hi Przemek,
On 1/22/20 5:37 AM, Przemyslaw Gomulka wrote:
Hello,
I am not sure this is the right place to ask, but I couldn't find answers
anywhere else.
I want my application to parse and format dates basing on start of the week
being Monday and requiring 4days in the first week of the year.
This was the behaviour existing previously in joda.org library, but seems like
this was now defaulted to start of the week Sunday and requires only 1day of
the week - looks like basing on US locale
I understand that I can specify a locale and this will allow me to parse my
dates with these rules.
However I have planty of formatters where I cannot tell what locale should be
used, and wanted to use Locale.ROOT which sadly defaults to Sunday,1.
I can workaround this with unicode extension “fw” for Locale.ROOT and default
to “sun”. I can’t find the extension for minimal days in the first week.
Loading a custom CalendarDataProvider works for me, but relies on a my Custom
implementation to be present on a classpath.
Both workarounds were introduced in JDK9.
JDK8 do not allow me to load SPI implementation from a classpath - requires
these classes to be placed in a jar in jre/lib/ext. Unfortunately I cannot
control what a user of the application will have in their JRE. It would be
great if https://bugs-stage.openjdk.java.net/browse/JDK-8167324 was also
backported to 8.
--
How can I work around in JDK8? Is there any other preferred way to achieve this?
--
Implementing your custom CalendarDataProvider is the right way to go. On
JDK8, you can use the system property "java.ext.dirs" to specify the
directory where extensions are loaded from, so that you will not need to
modify customer's JRE installations.
What was the reasoning to default to Sunday,1 ? I think it was incorrectly
assumed that this is common. As per incorrect in my opinion javadoc in
java.time.temporal.WeekFields.java:222 (jdk12)
* This week definition is in use in the US and other European countries.
*/
public static final WeekFields SUNDAY_START = WeekFields.of(DayOfWeek.SUNDAY,
1);
I am not sure the reason as I am not the designer for this, but it is
not surprising because Locale.US is the only required locale in the JDK:
https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/util/Locale.html#getAvailableLocales()
Naoto