-
Bug
-
Resolution: Fixed
-
P3
-
7
-
b07
-
generic
-
generic
-
Verified
The following code snippet shows a defect in implementation of toGregorianCalendar()
XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(1970, 1, 1, 0, 0, 0, 0, 0);
GregorianCalendar calendar = xmlCalendar.toGregorianCalendar();
int firstDayOfWeek = calendar.getFirstDayOfWeek();
Calendar defaultCalendar = Calendar.getInstance();
int defaultFirstDayOfWeek = defaultCalendar.getFirstDayOfWeek();
if ( firstDayOfWeek != defaultFirstDayOfWeek) {
return Status("Failed " + firstDayOfWeek + " != " + defaultFirstDayOfWeek);
}
--- Output: ----
Failed 1 != 2
----------------
It can be reproduced on Windows 7 en_US that has the following settings:
Control Panel - All Control Panel Items - Region and Laguage
Format:
Format Russian (Russia)
Location:
Current location:
Russia
The API documentation for toGregorianCalendar states:
public abstract GregorianCalendar toGregorianCalendar()
...
To ensure consistency in conversion implementations, the new GregorianCalendar should be instantiated in following manner.
* Using timeZone value as defined above, create a new java.util.GregorianCalendar(timeZone,Locale.getDefault())
...
The API documentation for getInstance states:
public static Calendar getInstance()
Gets a calendar using the default time zone and locale. The Calendar returned is based on the current time in the default time zone with the default locale.
Thus desired result is FirstDayOfWeek of GregorianCalendar should be equal to the FirstDayOfWeek of Calendar
XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(1970, 1, 1, 0, 0, 0, 0, 0);
GregorianCalendar calendar = xmlCalendar.toGregorianCalendar();
int firstDayOfWeek = calendar.getFirstDayOfWeek();
Calendar defaultCalendar = Calendar.getInstance();
int defaultFirstDayOfWeek = defaultCalendar.getFirstDayOfWeek();
if ( firstDayOfWeek != defaultFirstDayOfWeek) {
return Status("Failed " + firstDayOfWeek + " != " + defaultFirstDayOfWeek);
}
--- Output: ----
Failed 1 != 2
----------------
It can be reproduced on Windows 7 en_US that has the following settings:
Control Panel - All Control Panel Items - Region and Laguage
Format:
Format Russian (Russia)
Location:
Current location:
Russia
The API documentation for toGregorianCalendar states:
public abstract GregorianCalendar toGregorianCalendar()
...
To ensure consistency in conversion implementations, the new GregorianCalendar should be instantiated in following manner.
* Using timeZone value as defined above, create a new java.util.GregorianCalendar(timeZone,Locale.getDefault())
...
The API documentation for getInstance states:
public static Calendar getInstance()
Gets a calendar using the default time zone and locale. The Calendar returned is based on the current time in the default time zone with the default locale.
Thus desired result is FirstDayOfWeek of GregorianCalendar should be equal to the FirstDayOfWeek of Calendar
- relates to
-
JDK-4700857 RFE: separating user locale and user interface locale
- Closed