3

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?

oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449
  • http://en.wikipedia.org/wiki/ISO_week_date#Last_week might be a bit of help, although it doesn't explain why en locale results in week 1. Could timezones have anything to do with this? – Peeter Mar 21 '11 at 12:17
  • 3
    Isn't the case that `en_GB` means UK, while `en` is assumed to be US? And probably UK uses ISO week numbering and US use their own. – Grzegorz Oledzki Mar 21 '11 at 12:20
  • Cannot reproduce, jdk 1.6.0_21. – axtavt Mar 21 '11 at 12:30
  • @axtavt - interesting, I see the issue on all of 1.6.0_03, 1.6.0_18 and 1.6.0_24 – oxbow_lakes Mar 21 '11 at 13:24

2 Answers2

9

From ISO8601, week 1 is defined as the week containing January 4th. Since 2011-01-01 was a Saturday, this falls in the previous week.

Since there is no week 0, then 2011-01-01 can also be spelled as 2010-W52-6.

Those wacky Americans, on the other hand, allow for partial weeks. From Wikipedia:

The US system has weeks from Sunday through Saturday, and partial weeks at the beginning and the end of the year.

So, they would define it as being the last day of week 1.

Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121
3

for Europe 1 January 2011 W52 is correct.
This is ISO standard for definition of week 01

however various numberings exists for different countries. see Week_numbering

bw_üezi
  • 4,483
  • 4
  • 23
  • 41