-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.3.1
-
generic
-
generic
Name: bsC130419 Date: 06/29/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
Appended code illustrates the problem, which occurs when setFirstDayOfWeek()
and setMinimalDaysInFirstWeek() are used. Actual and expected output
noted in code comments.
May be related to bug 4459653
==============================================================
import java.util.*;
public class Test {
public static Calendar getDefaultCalendar() {
Calendar cal = Calendar.getInstance();
return cal;
}
public static Calendar getIsoCalendar() {
Calendar cal = Calendar.getInstance();
// ISO weeks start on a monday
cal.setFirstDayOfWeek(Calendar.MONDAY);
// The first ISO week of a year contains the first Thu of the year
cal.setMinimalDaysInFirstWeek(4);
return cal;
}
public static void main(String[] args) {
System.out.println("\nUsing ISO calendar:");
System.out.println("===================");
Calendar cal1 = getIsoCalendar();
cal1.set(2001, Calendar.AUGUST, 5);
int w1 = cal1.get(Calendar.WEEK_OF_YEAR);
System.out.println("Week number for Sun 5th Aug 2001: " + w1);
// Above line correctly prints week "31"
Calendar cal2 = getIsoCalendar();
cal2.set(Calendar.YEAR, 2001);
cal2.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
cal2.set(Calendar.WEEK_OF_YEAR, 31);
System.out.println(" Date for Sun in week 31 of 2001: " + cal2.getTime().toString());
// Above line should print week "Sun 5th Aug", no?
// Actually it prints "Sun Jul 29", which is in week 30.
System.out.println("\nUsing default calendar:");
System.out.println("=======================");
Calendar cal3 = getDefaultCalendar();
cal3.set(2001, Calendar.AUGUST, 5);
int w3 = cal3.get(Calendar.WEEK_OF_YEAR);
System.out.println("Week number for Sun 5th Aug 2001: " + w3);
// Prints week "32". Not sure what "default" means but let's play along.
Calendar cal4 = getDefaultCalendar();
cal4.set(Calendar.YEAR, 2001);
cal4.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
cal4.set(Calendar.WEEK_OF_YEAR, 32);
System.out.println(" Date for Sun in week 32 of 2001: " + cal4.getTime().toString());
// Prints "Sun 5th Aug 2001".
// Unlike the ISO case, this is at least consistent.
}
}
(Review ID: 127557)
======================================================================
- duplicates
-
JDK-4409072 Calendar.set() for WEEK_OF_MONTH & WEEK_OF_YEAR have problems in "ar" locale
-
- Resolved
-