It turns out that the week-of-year using ww
as a java date format string is 52 for the 1st January 2011 when the locale is en_GB
. Here is proof (using a scala REPL, though I could have done this using a Java program)
First get my locales
scala> val en = java.util.Locale.getAvailableLocales.find(_.toString == "en") getOrElse error("no en")
en: java.util.Locale = en
scala> val en_GB = java.util.Locale.getAvailableLocales.find(_.toString == "en_GB") getOrElse error("no en_GB")
en_GB: java.util.Locale = en_GB
Now make the 1st of Jan
scala> import java.util.Calendar; import Calendar._
import java.util.Calendar
import Calendar._
scala> Calendar.getInstance
res23: java.util.Calendar = java.util.GregorianCalendar[time=1300708839128,....]
scala> res23.set(MONTH, JANUARY); res23.set(DAY_OF_MONTH, 1)
scala> val firstJan = res23.getTime
firstJan: java.util.Date = Sat Jan 01 12:00:39 GMT 2011
Now declare a method to print this in a locale-dependent way:
scala> def weekInLocale(l : java.util.Locale) = { java.util.Locale.setDefault(l); new java.text.SimpleDateFormat("ww").format(firstJan) }
weekInLocale: (l: java.util.Locale)java.lang.String
Now invoke it:
scala> weekInLocale(en)
res24: java.lang.String = 01
scala> weekInLocale(en_GB)
res26: java.lang.String = 52
Is this right?