Calendar - a problem with Java?

From: Iain Downie (iain.downie_at_bto.org)
Date: 12/30/04


Date: Thu, 30 Dec 2004 10:30:21 -0000

Dear all,

we use the weeks of the year (all 52 of them) when collecting weekly batch
data from birdwatchers. Every few years, we have to invent a week 53 to
catch up, as there are on average 52.2 weeks a year from Jan 1 to Dec 31.
While this seems arbitrary, and probably done on a very ad-hoc basis, it
does fit quite nicely and we choose week 53 to appear when week 52 ends
about 25th Dec.

However, how does the Java Calendar object cope with this. If I do a

Calendar now = Calendar.getInstance();
now.get(Calendar.WEEK_OF_YEAR);
now.get(Calendar.MONTH);
now.get(Calendar.YEAR);

where 'now' is 30th Dec 2004, I get week = 1, month = 11 (OK, still Dec!)
and year = 2004.

While my ad-hoc invention of a week 53 seems bizarre, it doesn't help that
Java forces a wrong week when still in 2004. Has anyone else found this
problem......or am I using the wrong method to get the week of the year?

Regards, and happy new year when it comes.
Iain