These two questions prompted me to wonder what settings in Mac OS X affect the Locale and Calendar defaults and behavior in Java:
I've seen some peculiar behavior as to what affects these properties of java.util.Calendar.
The facts determined:
Locale
is determined by Language in System Preferences.Running this code as a test.
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
public class TestCalendar
{
public static void main( String[] args )
{
Locale locale = Locale.getDefault();
Calendar c = Calendar.getInstance();
c.setTime( new Date( new Long( 1293840000000l ) ) ); // First moment of the year 2011 in UTC.
System.out.println( "Locale: " + locale + " | FirstDayOfWeek: " + c.getFirstDayOfWeek() + " | MinimialDaysInFirstWeek: " + c.getMinimalDaysInFirstWeek() );
}
}
Using Mac OS X 10.8.5 (Mountain Lion) in a Parallels 9 virtual machine hosted on Mac OS X (Mavericks) with Java 8 Update 11 with a United States locale chosen during installation of the OS, I played around with System Preferences
> Language & Text
.
Strangely, changing First day of week
on the Region tab has no effect. Java reports FirstDayOfWeek: 1
whether I set that popup menu to "Sunday" or "Monday".
Locale: en_US | FirstDayOfWeek: 1 | MinimialDaysInFirstWeek: 1
Restarting the NetBeans IDE does not help. Restarting the Mac (virtual machine) does not help.
On the Region tab, check the Show all regions checkbox to see many more regions. Choose French
> France
. Run the IDE immediately. No need no restart the IDE or the OS, nor even to close the System Preferences window.
Locale: en_US | FirstDayOfWeek: 2 | MinimialDaysInFirstWeek: 4
Interesting on two accounts.
2
as FirstDayOfWeek means Monday
, as is correct for France (and much of the world).Resetting the Region popup back to United States
restores the Java properties, which is consistent and expected:
Locale: en_US | FirstDayOfWeek: 1 | MinimialDaysInFirstWeek: 1
On the Language tab, drag Français
(French) to the top of the list, so it appears before English.
Immediately run the IDE.
Locale: fr_FR | FirstDayOfWeek: 1 | MinimialDaysInFirstWeek: 1
Again, interesting. Now we know the Java Locale is determined by the Mac Language setting. And we know that has no effect on the Calendar properties in question.
So you think Mac Language determines Java Locale, and Java Locale does not affect the Calendar properties? Right, when reading above, but Wrong when reading on to next section where we see that Java Locale set another way can affect the Calendar properties. Very confusing.
Another contradiction found. Let's restore the Mac back to US defaults: (1) English at top of Language list, (2) Region set to United States.
Change our code to pass a Locale to the Calendar's constructor.
Calendar c = Calendar.getInstance( Locale.FRANCE );
This affects the Calendar properties:
FirstDayOfWeek: 2 | MinimialDaysInFirstWeek: 4
So, the confusing contradiction is: