2

Yesterday I have received the answer to a question here: WEEK_OF_YEAR inconsistent on different machines

(basically, learned how WEEK_OF_YEAR gets computed based on firstDayOfWeek and minimalDaysInFirstWeek)

But now I have a follow-up question - what other settings could be affecting a Calendar's ability to use the default locale? Because here's the behaviour that I am observing (having a correct en_US default locale):

Calendar c = Calendar.getInstance(); // should use the default locale, per docs
System.out.println(c.getFirstDayOfWeek());
System.out.println(c.getMinimalDaysInFirstWeek());
c = Calendar.getInstance(Locale.getDefault()); // provide the default explicitly
System.out.println(c.getFirstDayOfWeek());
System.out.println(c.getMinimalDaysInFirstWeek());

The output of running this is:

  • 2
  • 4
  • 1
  • 1

It looks even more absurd (setDefault to the results of getDefault...?!) if I run this in Clojure (a JVM language, so the behaviour is exactly the same):

user=> (.getFirstDayOfWeek  (java.util.Calendar/getInstance))
2
user=> (Locale/setDefault (Locale/getDefault))
nil
user=> (.getFirstDayOfWeek  (java.util.Calendar/getInstance))
1

The examples above are run without any JVM arguments whatsoever - so, my question is, where could the setting of 2 and 4 for the firstDayOfWeek and minimalDaysInWeek be coming from? And, perhaps most importantly - how do I fix them permanently?

Thanks!

Community
  • 1
  • 1
alexakarpov
  • 1,848
  • 2
  • 21
  • 39
  • FWIW, can't replicate your results (and you're missing a `;` at the end of the Java version of your example). Can't replicate it locally (I get `2/4/2/4`), nor on [ideone](http://ideone.com/OZr78p) (I get `1/1/1/1`), or a `compileonline.com`, or `jdoodle.com`, ... – T.J. Crowder Jul 19 '14 at 16:58
  • yeah, I didn't expect you could duplicate this - my system is borked in some subtle way. Hence my question, really - where _could_ this setting creep in from; what could affect the Calendar in such a way, effectively _bypassing_ the default Locale, which should be the source of such settings... – alexakarpov Jul 19 '14 at 17:02
  • Yeah, very weird. I've tried several different boxes: Multiple Linux versions, multiple Windows versions, and always get either `2/4/2/4` or `1/1/1/1`. – T.J. Crowder Jul 19 '14 at 17:06
  • Indeed; I've tried several machines myself, and so did my co-workers. Interestingly enough, when I nuked my entire OS (3rd day on the job, and the machine was pre-used, so who knows what could be wrong with it), things got normal. But as soon as I finished running all the scripts which are responsible for setting my env up, it re-surfaced again. So now I want to find what's broken in those scripts. – alexakarpov Jul 19 '14 at 17:08
  • @alexakarpov You should specify what kind of computers, operating systems, and versions of Java are at play. – Basil Bourque Jul 19 '14 at 20:48
  • 1
    This question and [the other](http://stackoverflow.com/q/24828014/642706) prompted me to experiment to determine what settings in Mac OS X may be affecting the Java Calendar properties in question by alexakarpov. I posted my results in [this question](http://stackoverflow.com/q/24844982/642706) and [this answer](http://stackoverflow.com/a/24845484/642706). Interesting results including one big surprise (a probable bug). – Basil Bourque Jul 19 '14 at 22:19
  • impressive work, Basil! – alexakarpov Jul 20 '14 at 07:52

0 Answers0