Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is first-day-of-week language-based or country-based on JVM?

Tags:

java

jvm

calendar

One can obtain the first day of week on JVM by calling Calendar.getInstance(locale).getFirstDayOfWeek(). Yet, is this information language-based, or country-based?

like image 871
Martin Vysny Avatar asked Feb 07 '19 11:02

Martin Vysny


2 Answers

As it turns out, this is JDK version-dependent. JDK8 returns first day of week based on language, so it returns SUNDAY for "en_FI" "en_US" and MONDAY for "fi_FI" and "fi_US".

However, JDK9 switched to the CLDR system which (more logically) uses country. So, JDK9 will return MONDAY both for "en_FI" and "fi_FI" locales, and will return SUNDAY for "fi_US" and "en_US".

See JEP 252 for more details.

Also, quoting from JDK-8203280:

To add an explanation to this behavior, the CLDR implementation is correct, i.e., the first day of week should be defined by the region, not by the language.

like image 147
Martin Vysny Avatar answered Nov 16 '22 21:11

Martin Vysny


According to the documentation, it is country-based: https://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#getFirstDayOfWeek()

Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

like image 1
Andreas Hartmann Avatar answered Nov 16 '22 21:11

Andreas Hartmann