F
Frank Lenaerts
Hello,
I seem to have encountered a strange problem with the java.util.Calendar
object. When the week starts on a Monday, no problems, but when it starts
on a Saturday... The problem is: when I try to set the WEEK_OF_YEAR
property for 2004, 2005, 2006 (haven't tested it further), it always returns
a week before the week I want to set. With 2003 everything's ok. An
example of the used code:
### CODE ###
// Code used in the main thread ...
Calendar cal = Calendar.getInstance();
cal = Util.setWeekOfYear(cal, week, year);
// Somewhere else ...
public static Calendar setWeekOfYear(Calendar cal, int weekOfYear, int year)
{
cal.setMinimalDaysInFirstWeek(4);
cal.setFirstDayOfWeek(Calendar.SATURDAY)
cal.set(Calendar.YEAR, year);
cal.set(Calendar.WEEK_OF_YEAR, weekOfYear);
System.out.println("[UTIL] date: " +
GlobalDateFormatter.format(cal.getTime()));
System.out.println("[UTIL] week: " + cal.get(Calendar.WEEK_OF_YEAR));
return cal;
}
### OUTPUT ###
The good situation
(week = 1; year = 2003):
[UTIL] date: 05/01/2003
[UTIL] week: 1
(week = 30; year = 2003):
[UTIL] date: 27/07/2003
[UTIL] week: 30
The bad situation
(week = 1; year = 2004):
[UTIL] date: 29/12/2003
[UTIL] week: 52
(week = 30; year = 2004):
[UTIL] date: 19/07/2004
[UTIL] week: 29
Anyone knows what the problem could be ? We're using JDK 1.3.0-C. Thank
you very much in advance!
Frank
I seem to have encountered a strange problem with the java.util.Calendar
object. When the week starts on a Monday, no problems, but when it starts
on a Saturday... The problem is: when I try to set the WEEK_OF_YEAR
property for 2004, 2005, 2006 (haven't tested it further), it always returns
a week before the week I want to set. With 2003 everything's ok. An
example of the used code:
### CODE ###
// Code used in the main thread ...
Calendar cal = Calendar.getInstance();
cal = Util.setWeekOfYear(cal, week, year);
// Somewhere else ...
public static Calendar setWeekOfYear(Calendar cal, int weekOfYear, int year)
{
cal.setMinimalDaysInFirstWeek(4);
cal.setFirstDayOfWeek(Calendar.SATURDAY)
cal.set(Calendar.YEAR, year);
cal.set(Calendar.WEEK_OF_YEAR, weekOfYear);
System.out.println("[UTIL] date: " +
GlobalDateFormatter.format(cal.getTime()));
System.out.println("[UTIL] week: " + cal.get(Calendar.WEEK_OF_YEAR));
return cal;
}
### OUTPUT ###
The good situation
(week = 1; year = 2003):
[UTIL] date: 05/01/2003
[UTIL] week: 1
(week = 30; year = 2003):
[UTIL] date: 27/07/2003
[UTIL] week: 30
The bad situation
(week = 1; year = 2004):
[UTIL] date: 29/12/2003
[UTIL] week: 52
(week = 30; year = 2004):
[UTIL] date: 19/07/2004
[UTIL] week: 29
Anyone knows what the problem could be ? We're using JDK 1.3.0-C. Thank
you very much in advance!
Frank