--- old/src/java.base/share/classes/java/util/Calendar.java 2017-11-10 15:30:21.920396534 -0800
+++ new/src/java.base/share/classes/java/util/Calendar.java 2017-11-10 15:30:21.548389580 -0800
@@ -58,6 +58,7 @@
import sun.util.calendar.ZoneInfo;
import sun.util.locale.provider.CalendarDataUtility;
import sun.util.locale.provider.LocaleProviderAdapter;
+import sun.util.locale.provider.TimeZoneNameUtility;
import sun.util.spi.CalendarProvider;
/**
@@ -128,9 +129,14 @@
*
* Calendar
defines a locale-specific seven day week using two
* parameters: the first day of the week and the minimal days in first week
- * (from 1 to 7). These numbers are taken from the locale resource data when a
- * Calendar
is constructed. They may also be specified explicitly
- * through the methods for setting their values.
+ * (from 1 to 7). These numbers are taken from the locale resource data or the
+ * locale itself when a Calendar
is constructed. If the designated
+ * locale contains "fw" and/or "rg"
+ * Unicode extensions, the first day of the week will be obtained according to
+ * those extensions. If both "fw" and "rg" are specified, the value from "fw"
+ * extension supersedes the implicit one from "rg" extension.
+ * They may also be specified explicitly through the methods for setting their
+ * values.
*
*
When setting or getting the WEEK_OF_MONTH
or
* WEEK_OF_YEAR
fields, Calendar
must determine the
@@ -1463,7 +1469,7 @@
locale = Locale.getDefault();
}
if (zone == null) {
- zone = TimeZone.getDefault();
+ zone = defaultTimeZone(locale);
}
Calendar cal;
if (type == null) {
@@ -1610,7 +1616,8 @@
*/
public static Calendar getInstance()
{
- return createCalendar(TimeZone.getDefault(), Locale.getDefault(Locale.Category.FORMAT));
+ Locale aLocale = Locale.getDefault(Locale.Category.FORMAT);
+ return createCalendar(defaultTimeZone(aLocale), aLocale);
}
/**
@@ -1637,7 +1644,7 @@
*/
public static Calendar getInstance(Locale aLocale)
{
- return createCalendar(TimeZone.getDefault(), aLocale);
+ return createCalendar(defaultTimeZone(aLocale), aLocale);
}
/**
@@ -1655,6 +1662,16 @@
return createCalendar(zone, aLocale);
}
+ private static TimeZone defaultTimeZone(Locale l) {
+ TimeZone defaultTZ = TimeZone.getDefault();
+ String shortTZID = l.getUnicodeLocaleType("tz");
+ return shortTZID != null ?
+ TimeZoneNameUtility.convertLDMLShortID(shortTZID)
+ .map(TimeZone::getTimeZone)
+ .orElse(defaultTZ) :
+ defaultTZ;
+ }
+
private static Calendar createCalendar(TimeZone zone,
Locale aLocale)
{