< prev index next >
src/java.base/share/classes/java/util/Calendar.java
Print this page
rev 47733 : 8176841: Additional Unicode Language-Tag Extensions
8189134: New system properties for the default Locale extensions
Reviewed-by:
*** 56,65 ****
--- 56,66 ----
import java.util.concurrent.ConcurrentMap;
import sun.util.BuddhistCalendar;
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;
/**
* The <code>Calendar</code> class is an abstract class that provides methods
* for converting between a specific instant in time and a set of {@link
*** 126,138 ****
*
* <h4><a id="first_week">First Week</a></h4>
*
* <code>Calendar</code> 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
! * <code>Calendar</code> is constructed. They may also be specified explicitly
! * through the methods for setting their values.
*
* <p>When setting or getting the <code>WEEK_OF_MONTH</code> or
* <code>WEEK_OF_YEAR</code> fields, <code>Calendar</code> must determine the
* first week of the month or year as a reference point. The first week of a
* month or year is defined as the earliest seven day period beginning on
--- 127,144 ----
*
* <h4><a id="first_week">First Week</a></h4>
*
* <code>Calendar</code> 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 or the
! * locale itself when a <code>Calendar</code> is constructed. If the designated
! * locale contains "fw" and/or "rg" <a href="./Locale.html#def_locale_extension">
! * Unicode extensions</a>, 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.
*
* <p>When setting or getting the <code>WEEK_OF_MONTH</code> or
* <code>WEEK_OF_YEAR</code> fields, <code>Calendar</code> must determine the
* first week of the month or year as a reference point. The first week of a
* month or year is defined as the earliest seven day period beginning on
*** 1461,1471 ****
public Calendar build() {
if (locale == null) {
locale = Locale.getDefault();
}
if (zone == null) {
! zone = TimeZone.getDefault();
}
Calendar cal;
if (type == null) {
type = locale.getUnicodeLocaleType("ca");
}
--- 1467,1477 ----
public Calendar build() {
if (locale == null) {
locale = Locale.getDefault();
}
if (zone == null) {
! zone = defaultTimeZone(locale);
}
Calendar cal;
if (type == null) {
type = locale.getUnicodeLocaleType("ca");
}
*** 1608,1618 ****
*
* @return a Calendar.
*/
public static Calendar getInstance()
{
! return createCalendar(TimeZone.getDefault(), Locale.getDefault(Locale.Category.FORMAT));
}
/**
* Gets a calendar using the specified time zone and default locale.
* The <code>Calendar</code> returned is based on the current time
--- 1614,1625 ----
*
* @return a Calendar.
*/
public static Calendar getInstance()
{
! Locale aLocale = Locale.getDefault(Locale.Category.FORMAT);
! return createCalendar(defaultTimeZone(aLocale), aLocale);
}
/**
* Gets a calendar using the specified time zone and default locale.
* The <code>Calendar</code> returned is based on the current time
*** 1635,1645 ****
* @param aLocale the locale for the week data
* @return a Calendar.
*/
public static Calendar getInstance(Locale aLocale)
{
! return createCalendar(TimeZone.getDefault(), aLocale);
}
/**
* Gets a calendar with the specified time zone and locale.
* The <code>Calendar</code> returned is based on the current time
--- 1642,1652 ----
* @param aLocale the locale for the week data
* @return a Calendar.
*/
public static Calendar getInstance(Locale aLocale)
{
! return createCalendar(defaultTimeZone(aLocale), aLocale);
}
/**
* Gets a calendar with the specified time zone and locale.
* The <code>Calendar</code> returned is based on the current time
*** 1653,1662 ****
--- 1660,1679 ----
Locale aLocale)
{
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)
{
CalendarProvider provider =
LocaleProviderAdapter.getAdapter(CalendarProvider.class, aLocale)
< prev index next >