< prev index next >

src/java.base/share/classes/java/util/Calendar.java

Print this page
rev 47925 : 8191349: Add a new method in j.t.f.DateTimeFormatter to reflect Unicode extensions
Reviewed-by:


1433         /**
1434          * Returns a {@code Calendar} built from the parameters set by the
1435          * setter methods. The calendar type given by the {@link #setCalendarType(String)
1436          * setCalendarType} method or the {@linkplain #setLocale(Locale) locale} is
1437          * used to determine what {@code Calendar} to be created. If no explicit
1438          * calendar type is given, the locale's default calendar is created.
1439          *
1440          * <p>If the calendar type is {@code "iso8601"}, the
1441          * {@linkplain GregorianCalendar#setGregorianChange(Date) Gregorian change date}
1442          * of a {@link GregorianCalendar} is set to {@code Date(Long.MIN_VALUE)}
1443          * to be the <em>proleptic</em> Gregorian calendar. Its week definition
1444          * parameters are also set to be <a
1445          * href="GregorianCalendar.html#iso8601_compatible_setting">compatible
1446          * with the ISO 8601 standard</a>. Note that the
1447          * {@link GregorianCalendar#getCalendarType() getCalendarType} method of
1448          * a {@code GregorianCalendar} created with {@code "iso8601"} returns
1449          * {@code "gregory"}.
1450          *
1451          * <p>The default values are used for locale and time zone if these
1452          * parameters haven't been given explicitly.





1453          *
1454          * <p>Any out of range field values are either normalized in lenient
1455          * mode or detected as an invalid value in non-lenient mode.
1456          *
1457          * @return a {@code Calendar} built with parameters of this {@code
1458          *         Calendar.Builder}
1459          * @throws IllegalArgumentException if the calendar type is unknown, or
1460          *             if any invalid field values are given in non-lenient mode, or
1461          *             if a week date is given for the calendar type that doesn't
1462          *             support week dates.
1463          * @see Calendar#getInstance(TimeZone, Locale)
1464          * @see Locale#getDefault(Locale.Category)
1465          * @see TimeZone#getDefault()
1466          */
1467         public Calendar build() {
1468             if (locale == null) {
1469                 locale = Locale.getDefault();
1470             }
1471             if (zone == null) {
1472                 zone = defaultTimeZone(locale);


1594      * Constructs a calendar with the specified time zone and locale.
1595      *
1596      * @param zone the time zone to use
1597      * @param aLocale the locale for the week data
1598      */
1599     protected Calendar(TimeZone zone, Locale aLocale)
1600     {
1601         fields = new int[FIELD_COUNT];
1602         isSet = new boolean[FIELD_COUNT];
1603         stamp = new int[FIELD_COUNT];
1604 
1605         this.zone = zone;
1606         setWeekCountData(aLocale);
1607     }
1608 
1609     /**
1610      * Gets a calendar using the default time zone and locale. The
1611      * <code>Calendar</code> returned is based on the current time
1612      * in the default time zone with the default
1613      * {@link Locale.Category#FORMAT FORMAT} locale.




1614      *
1615      * @return a Calendar.
1616      */
1617     public static Calendar getInstance()
1618     {
1619         Locale aLocale = Locale.getDefault(Locale.Category.FORMAT);
1620         return createCalendar(defaultTimeZone(aLocale), aLocale);
1621     }
1622 
1623     /**
1624      * Gets a calendar using the specified time zone and default locale.
1625      * The <code>Calendar</code> returned is based on the current time
1626      * in the given time zone with the default
1627      * {@link Locale.Category#FORMAT FORMAT} locale.
1628      *
1629      * @param zone the time zone to use
1630      * @return a Calendar.
1631      */
1632     public static Calendar getInstance(TimeZone zone)
1633     {
1634         return createCalendar(zone, Locale.getDefault(Locale.Category.FORMAT));
1635     }
1636 
1637     /**
1638      * Gets a calendar using the default time zone and specified locale.
1639      * The <code>Calendar</code> returned is based on the current time
1640      * in the default time zone with the given locale.




1641      *
1642      * @param aLocale the locale for the week data
1643      * @return a Calendar.
1644      */
1645     public static Calendar getInstance(Locale aLocale)
1646     {
1647         return createCalendar(defaultTimeZone(aLocale), aLocale);
1648     }
1649 
1650     /**
1651      * Gets a calendar with the specified time zone and locale.
1652      * The <code>Calendar</code> returned is based on the current time
1653      * in the given time zone with the given locale.
1654      *
1655      * @param zone the time zone to use
1656      * @param aLocale the locale for the week data
1657      * @return a Calendar.
1658      */
1659     public static Calendar getInstance(TimeZone zone,
1660                                        Locale aLocale)




1433         /**
1434          * Returns a {@code Calendar} built from the parameters set by the
1435          * setter methods. The calendar type given by the {@link #setCalendarType(String)
1436          * setCalendarType} method or the {@linkplain #setLocale(Locale) locale} is
1437          * used to determine what {@code Calendar} to be created. If no explicit
1438          * calendar type is given, the locale's default calendar is created.
1439          *
1440          * <p>If the calendar type is {@code "iso8601"}, the
1441          * {@linkplain GregorianCalendar#setGregorianChange(Date) Gregorian change date}
1442          * of a {@link GregorianCalendar} is set to {@code Date(Long.MIN_VALUE)}
1443          * to be the <em>proleptic</em> Gregorian calendar. Its week definition
1444          * parameters are also set to be <a
1445          * href="GregorianCalendar.html#iso8601_compatible_setting">compatible
1446          * with the ISO 8601 standard</a>. Note that the
1447          * {@link GregorianCalendar#getCalendarType() getCalendarType} method of
1448          * a {@code GregorianCalendar} created with {@code "iso8601"} returns
1449          * {@code "gregory"}.
1450          *
1451          * <p>The default values are used for locale and time zone if these
1452          * parameters haven't been given explicitly.
1453          * <p>
1454          * If the locale contains the time zone with "tz"
1455          * <a href="Locale.html#def_locale_extension">Unicode extension</a>,
1456          * and time zone hasn't been given explicitly, time zone in the locale
1457          * is used.
1458          *
1459          * <p>Any out of range field values are either normalized in lenient
1460          * mode or detected as an invalid value in non-lenient mode.
1461          *
1462          * @return a {@code Calendar} built with parameters of this {@code
1463          *         Calendar.Builder}
1464          * @throws IllegalArgumentException if the calendar type is unknown, or
1465          *             if any invalid field values are given in non-lenient mode, or
1466          *             if a week date is given for the calendar type that doesn't
1467          *             support week dates.
1468          * @see Calendar#getInstance(TimeZone, Locale)
1469          * @see Locale#getDefault(Locale.Category)
1470          * @see TimeZone#getDefault()
1471          */
1472         public Calendar build() {
1473             if (locale == null) {
1474                 locale = Locale.getDefault();
1475             }
1476             if (zone == null) {
1477                 zone = defaultTimeZone(locale);


1599      * Constructs a calendar with the specified time zone and locale.
1600      *
1601      * @param zone the time zone to use
1602      * @param aLocale the locale for the week data
1603      */
1604     protected Calendar(TimeZone zone, Locale aLocale)
1605     {
1606         fields = new int[FIELD_COUNT];
1607         isSet = new boolean[FIELD_COUNT];
1608         stamp = new int[FIELD_COUNT];
1609 
1610         this.zone = zone;
1611         setWeekCountData(aLocale);
1612     }
1613 
1614     /**
1615      * Gets a calendar using the default time zone and locale. The
1616      * <code>Calendar</code> returned is based on the current time
1617      * in the default time zone with the default
1618      * {@link Locale.Category#FORMAT FORMAT} locale.
1619      * <p>
1620      * If the locale contains the time zone with "tz"
1621      * <a href="Locale.html#def_locale_extension">Unicode extension</a>,
1622      * that time zone is used instead.
1623      *
1624      * @return a Calendar.
1625      */
1626     public static Calendar getInstance()
1627     {
1628         Locale aLocale = Locale.getDefault(Locale.Category.FORMAT);
1629         return createCalendar(defaultTimeZone(aLocale), aLocale);
1630     }
1631 
1632     /**
1633      * Gets a calendar using the specified time zone and default locale.
1634      * The <code>Calendar</code> returned is based on the current time
1635      * in the given time zone with the default
1636      * {@link Locale.Category#FORMAT FORMAT} locale.
1637      *
1638      * @param zone the time zone to use
1639      * @return a Calendar.
1640      */
1641     public static Calendar getInstance(TimeZone zone)
1642     {
1643         return createCalendar(zone, Locale.getDefault(Locale.Category.FORMAT));
1644     }
1645 
1646     /**
1647      * Gets a calendar using the default time zone and specified locale.
1648      * The <code>Calendar</code> returned is based on the current time
1649      * in the default time zone with the given locale.
1650      * <p>
1651      * If the locale contains the time zone with "tz"
1652      * <a href="Locale.html#def_locale_extension">Unicode extension</a>,
1653      * that time zone is used instead.
1654      *
1655      * @param aLocale the locale for the week data
1656      * @return a Calendar.
1657      */
1658     public static Calendar getInstance(Locale aLocale)
1659     {
1660         return createCalendar(defaultTimeZone(aLocale), aLocale);
1661     }
1662 
1663     /**
1664      * Gets a calendar with the specified time zone and locale.
1665      * The <code>Calendar</code> returned is based on the current time
1666      * in the given time zone with the given locale.
1667      *
1668      * @param zone the time zone to use
1669      * @param aLocale the locale for the week data
1670      * @return a Calendar.
1671      */
1672     public static Calendar getInstance(TimeZone zone,
1673                                        Locale aLocale)


< prev index next >