Home | History | Annotate | Download | only in util

Lines Matching refs:calendar

19  * {@icuenhanced java.util.Calendar}.{@icu _usage_}
21 * <p><code>Calendar</code> is an abstract base class for converting between
29 * <p>Subclasses of <code>Calendar</code> interpret a <code>Date</code>
30 * according to the rules of a specific calendar system. ICU4J contains
31 * several subclasses implementing different international calendar systems.
34 * Like other locale-sensitive classes, <code>Calendar</code> provides a
36 * object of this type. <code>Calendar</code>'s <code>getInstance</code> method
37 * returns a calendar of a type appropriate to the locale, whose
40 * <pre>Calendar rightNow = Calendar.getInstance()</pre>
44 * '<code>calendar</code>' tag and value are retrieved if present. If a recognized
45 * value is supplied, a calendar is provided and configured as appropriate.
49 * <pre>Calendar cal = Calendar.getInstance(new ULocale("en_US@calendar=japanese"));</pre>
53 * <p>A <code>Calendar</code> object can produce all the time field values
55 * calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
56 * <code>Calendar</code> defines the range of values returned by certain fields,
63 * <p>When a <code>Calendar</code> is <em>lenient</em>, it accepts a wider range
73 * <p><code>Calendar</code> defines a locale-specific seven day week using two
76 * <code>Calendar</code> is constructed. They may also be specified explicitly
80 * <code>WEEK_OF_YEAR</code> fields, <code>Calendar</code> must determine the
87 * different. For example, a specific <code>Calendar</code> subclass may
97 * <p><strong>Insufficient information.</strong> The calendar will use default
98 * information to specify the missing fields. This may vary by calendar; for
99 * the Gregorian calendar, the default for a field is the same as that of the
102 * <p><strong>Inconsistent information.</strong> If fields conflict, the calendar
104 * determining the day, the calendar will look for one of the following
127 * specification of the historial Arabic astronomical calendar requires year,
143 * calendar, as those must be modifiable or overridable by the user at
149 * <p><code>Calendar</code> fields can be changed using three methods:
156 * the calendar's milliseconds is not recomputed until the next call to
162 * field, the field value, and the calendar system. In addition,
165 * the concrete calendar class.</p>
168 * originally set to August 31, 1999. Calling <code>set(Calendar.MONTH,
169 * Calendar.SEPTEMBER)</code> sets the calendar to September 31,
172 * call to <code>set(Calendar.DAY_OF_MONTH, 30)</code> before the call to
173 * <code>getTime()</code> sets the calendar to September 30, 1999, since
195 * that are not expected to be invariant. The calendar system
200 * an immediate recomputation of the calendar's milliseconds and all
204 * originally set to August 31, 1999. Calling <code>add(Calendar.MONTH,
205 * 13)</code> sets the calendar to September 30, 2000. <strong>Add rule
228 * originally set to August 31, 1999. Calling <code>roll(Calendar.MONTH,
229 * 8)</code> sets the calendar to April 30, <strong>1999</strong>. Add
238 * <code>roll(Calendar.WEEK_OF_MONTH, -1)</code> sets the calendar to
240 * <code>add(Calendar.WEEK_OF_MONTH, -1)</code> sets the calendar to
266 * of a <tt>Calendar</tt>. It is quite possible for <tt>Calendar</tt> subclasses
272 * <p><big><big><b>Calendar Architecture in ICU4J</b></big></big></p>
274 * <p>Recently the implementation of <code>Calendar</code> has changed
276 * <code>Calendar</code> class was designed to support subclassing, but
278 * With the implementation of several new calendar subclasses, including
283 * ways in which <code>com.ibm.icu.util.Calendar</code> differs from
284 * <code>java.util.Calendar</code>.
289 * <p>Overview of changes between the classic <code>Calendar</code>
308 * <code>Calendar</code> base class. As a result, it is much easier
309 * to subclass <code>Calendar</code>. <b>Motivation:</b> Subclasses
311 * common across calendar systems: The definition and behavior of
318 * <li>The <code>Calendar</code> base class contains some Gregorian
319 * calendar algorithmic support that subclasses can use (specifically
323 * <code>Calendar</code> subclasses in order to implement consistent
331 * calendar systems.</li>
339 * <code>Calendar</code> protected constants should be used.
357 * defined in <code>Calendar</code>.</li>
359 * <li>New API has been added to support calendar-specific subclasses
363 * various international calendar systems.</li>
369 * <p>The original <code>Calendar</code> API was based on the experience
383 * Gregorian calendar. This is based on two things: (1) Many calendars
384 * are based on the Gregorian calendar (such as the Buddhist and Japanese
389 * <code>Calendar</code>. Subclasses no longer compute the week related
399 * are computed by <code>Calendar</code>.
408 * are calendar-specific fields not defined by <code>Calendar</code>,
413 * <code>Calendar</code> implements a proleptic Gregorian
414 * calendar. Within this method, subclasses may call
415 * <code>getGregorianXxx()</code> to obtain the Gregorian calendar
423 * <code>Calendar</code>. <code>Calendar</code> determines which fields
425 * addition, <code>Calendar</code> handles the computation of the time
434 * to return the extended year for this calendar system, based on the
436 * the calendar system uses that are larger than a year, such as
471 * respect to calendar system) and are handled by the base
484 * array large enough to hold the calendar's fields. This is only
485 * necessary if the calendar defines additional fields beyond those
486 * defined by <code>Calendar</code>. The length of the result must be
491 * <code>DateFormat</code> appropriate to this calendar. This is only
492 * required if a calendar subclass redefines the use of a field (for
498 * example, in the Hebrew calendar the month &quot;Adar I&quot; only
499 * occurs in leap years; in other years the calendar jumps from
513 * calendar systems and implemented in <code>Calendar</code>.
517 * <li>Time is normalized. Even though some calendar systems transition
521 * <code>Calendar</code> and to maintain basic correpsondences
522 * between calendar systems. Affected fields: {@link #AM_PM},
528 * computed the same for all calendar systems, and depends on the
531 * {@link #DAY_OF_MONTH}. As a result, <code>Calendar</code>
532 * always computes these fields, even for non-Gregorian calendar
540 * although the Gregorian calendar introduced a discontinuity when
554 * <p>The allowable range of <code>Calendar</code> has been
560 * boundaries. The new <code>Calendar</code> protocol specifies the
564 * should use the protected constants in <code>Calendar</code> to
572 * even though the Gregorian calendar was not instituted until the
574 * dates before the historical onset of the calendar by extending the
575 * calendar system backward in time. Similarly, the
579 * calendar system. Instead, they implement
582 * calendar is set to not be lenient, out-of-range field values will
585 * <li>Calendar system subclasses compute a <em>extended
590 * Gregorian calendar, the {@link #EXTENDED_YEAR} is computed as
595 * + 20 * BAKTUN)</code>. The <code>Calendar</code> base class uses
608 public class Calendar implements Serializable, Cloneable, Comparable<Calendar> {
614 public final java.util.Calendar calendar;
618 * @param delegate the Calendar to which to delegate
620 public Calendar(java.util.Calendar delegate) {
621 this.calendar = delegate;
624 // Data flow in Calendar
627 // The current time is represented in two ways by Calendar: as UTC
631 // conversion is encapsulated by a TimeZone object owned by the Calendar.
638 // This is implemented by the Calendar subclass's computeTime() method.
645 // | Using Calendar-specific algorithm
654 // follows. This is implemented by the Calendar subclass's computeFields()
663 // | Using Calendar-specific algorithm
671 // the Calendar is lenient, the fields are also renormalized to standard
676 * era, e.g., AD or BC in the Julian calendar. This is a calendar-specific
686 * year. This is a calendar-specific value; see subclass documentation.
693 * month. This is a calendar-specific value. The first month of the year is
893 // * the year of this calendar system, encompassing all supra-year
894 // * fields. For example, for the Julian calendar system, year numbers
896 // * the Julian calendar system assigns positive values to CE years and
1174 * Constructs a Calendar with the default time zone
1179 protected Calendar()
1185 * Constructs a calendar with the specified time zone and locale.
1190 protected Calendar(TimeZone zone, Locale aLocale)
1196 * Constructs a calendar with the specified time zone and locale.
1201 protected Calendar(TimeZone zone, ULocale locale)
1203 calendar = java.util.Calendar.getInstance(zone.timeZone, locale.toLocale());
1207 * Returns a calendar using the default time zone and locale.
1208 * @return a Calendar.
1211 public static synchronized Calendar getInstance()
1213 return new Calendar(java.util.Calendar.getInstance(ULocale.getDefault(Category.FORMAT).toLocale()));
1217 * Returns a calendar using the specified time zone and default locale.
1219 * @return a Calendar.
1222 public static synchronized Calendar getInstance(TimeZone zone)
1224 return new Calendar(java.util.Calendar.getInstance(zone.timeZone, ULocale.getDefault(Category.FORMAT).toLocale()));
1228 * Returns a calendar using the default time zone and specified locale.
1230 * @return a Calendar.
1233 public static synchronized Calendar getInstance(Locale aLocale)
1235 return new Calendar(java.util.Calendar.getInstance(aLocale));
1239 * Returns a calendar using the default time zone and specified locale.
1241 * @return a Calendar.
1244 public static synchronized Calendar getInstance(ULocale locale)
1246 return new Calendar(java.util.Calendar.getInstance(locale.toLocale()));
1250 * Returns a calendar with the specified time zone and locale.
1253 * @return a Calendar.
1256 public static synchronized Calendar getInstance(TimeZone zone,
1258 return new Calendar(java.util.Calendar.getInstance(zone.timeZone, aLocale));
1262 * Returns a calendar with the specified time zone and locale.
1265 * @return a Calendar.
1268 public static synchronized Calendar getInstance(TimeZone zone,
1270 return new Calendar(java.util.Calendar.getInstance(zone.timeZone, locale.toLocale()));
1280 return java.util.Calendar.getAvailableLocales();
1292 synchronized (Calendar.class) {
1313 // * "calendar" is supported.
1327 * Returns this Calendar's current time.
1332 return calendar.getTime();
1336 * Sets this Calendar's current time with the given Date.
1345 calendar.setTime(date);
1349 * Returns this Calendar's current time as a long.
1354 return calendar.getTimeInMillis();
1358 * Sets this Calendar's current time from the given long value.
1363 calendar.setTimeInMillis(millis);
1374 return calendar.get(getJDKField(field));
1385 calendar.set(getJDKField(field), value);
1400 calendar.set(getJDKField(YEAR), year);
1401 calendar.set(getJDKField(MONTH), month);
1402 calendar.set(getJDKField(DATE), date);
1419 calendar.set(getJDKField(YEAR), year);
1420 calendar.set(getJDKField(MONTH), month);
1421 calendar.set(getJDKField(DATE), date);
1422 calendar.set(getJDKField(HOUR_OF_DAY), hour);
1423 calendar.set(getJDKField(MINUTE), minute);
1442 calendar.set(getJDKField(YEAR), year);
1443 calendar.set(getJDKField(MONTH), month);
1444 calendar.set(getJDKField(DATE), date);
1445 calendar.set(getJDKField(HOUR_OF_DAY), hour);
1446 calendar.set(getJDKField(MINUTE), minute);
1447 calendar.set(getJDKField(SECOND), second);
1456 calendar.clear();
1466 calendar.clear(getJDKField(field));
1476 return calendar.isSet(getJDKField(field));
1480 * Compares this calendar to the specified object.
1482 * not <code>null</code> and is a <code>Calendar</code> object that
1483 * represents the same calendar as this object.
1491 return calendar.equals(((Calendar)obj).calendar);
1498 * {@icu} Returns true if the given Calendar object is equivalent to this
1499 * one. An equivalent Calendar will behave exactly as this one
1501 * the equals() method to return true, the other Calendar must
1504 * @param other the Calendar to be compared with this Calendar
1507 public boolean isEquivalentTo(Calendar other) {
1508 return calendar.getClass() == other.calendar.getClass() &&
1509 calendar.isLenient() == other.calendar.isLenient() &&
1510 calendar.getFirstDayOfWeek() == other.calendar.getFirstDayOfWeek() &&
1511 calendar.getMinimalDaysInFirstWeek() == other.calendar.getMinimalDaysInFirstWeek() &&
1512 calendar.getTimeZone().equals(other.calendar.getTimeZone());
1516 * Returns a hash code for this calendar.
1521 return calendar.hashCode();
1526 * calendar is set to and the moment the given calendar or Date object
1531 if (that instanceof Calendar) {
1532 thatMs = ((Calendar)that).getTimeInMillis();
1536 throw new IllegalArgumentException(that + "is not a Calendar or Date");
1544 * @param when the Calendar to be compared with this Calendar.
1545 * @return true if the current time of this Calendar is before
1546 * the time of Calendar when; false otherwise.
1556 * @param when the Calendar to be compared with this Calendar.
1557 * @return true if the current time of this Calendar is after
1558 * the time of Calendar when; false otherwise.
1583 * @return the maximum of the given field for the current date of this calendar
1589 return calendar.getActualMaximum(getJDKField(field));
1608 * @return the minimum of the given field for the current date of this calendar
1615 return calendar.getActualMinimum(getJDKField(field));
1639 * <tt>roll(Calendar.MONTH, 2)</tt>, the result will be March 31, 1995.
1640 * But if you call <tt>roll(Calendar.MONTH, true)</tt>, the result will be
1646 * of a <tt>Calendar</tt>. It is quite possible for <tt>Calendar</tt> subclasses
1652 * @param field the calendar field to roll.
1666 calendar.roll(getJDKField(field), up);
1672 * <code>roll(Calendar.DATE, 3)</code>. If the
1675 * For example, calling <code>roll(Calendar.DATE, 10)</code>
1676 * on a Gregorian calendar set to 4/25/96 will result in the date 4/5/96.
1691 * of a <tt>Calendar</tt>. It is quite possible for <tt>Calendar</tt> subclasses
1709 * For example, in the Hebrew calendar the month "Adar I"
1710 * only occurs in leap years; in other years the calendar jumps from
1716 * @param field the calendar field to roll.
1726 calendar.roll(getJDKField(field), amount);
1730 * Add a signed amount to a specified field, using this calendar's rules.
1732 * <code>add(Calendar.DATE, 3)</code>.
1747 * of a <tt>Calendar</tt>. It is quite possible for <tt>Calendar</tt> subclasses
1763 * For example, in the Hebrew calendar the month "Adar I"
1764 * only occurs in leap years; in other years the calendar jumps from
1779 calendar.add(getJDKField(field), amount);
1782 private static String _getDisplayName(Calendar cal) {
1785 return "Japanese Calendar";
1787 return "Buddhist Calendar";
1789 return "Gregorian Calendar";
1793 * Returns the name of this calendar in the language of the given locale.
1801 * Returns the name of this calendar in the language of the given locale.
1810 * <code>Calendar</code> objects.
1812 * @param that the <code>Calendar</code> to compare to this.
1814 * this <code>Calendar</code> is equal to the time represented
1815 * by that <code>Calendar</code>, a value less than
1821 * <code>Calendar</code> is null.
1823 * <code>Calendar</code> can't be obtained because of invalid
1824 * calendar values.
1827 public int compareTo(Calendar that) {
1828 return calendar.compareTo(that.calendar);
1836 * {@icu} Returns a <code>DateFormat</code> appropriate to this calendar.
1844 return DateFormat.getDateInstance((Calendar)this.clone(), dateStyle, loc);
1846 return DateFormat.getDateTimeInstance((Calendar)this.clone(), dateStyle, timeStyle, loc);
1849 return DateFormat.getTimeInstance((Calendar)this.clone(), timeStyle, loc);
1856 * {@icu} Returns a <code>DateFormat</code> appropriate to this calendar.
1871 * calendar object is set to. If this calendar is set
1873 * positive. If this calendar is set <em>after</em> the given
1877 * Calendar.MONTH)</code> returns 3, then this calendar is set to
1881 * <p>As a side effect of this call, this calendar is advanced
1891 * int y = cal.fieldDifference(when, Calendar.YEAR);
1892 * int m = cal.fieldDifference(when, Calendar.MONTH);
1893 * int d = cal.fieldDifference(when, Calendar.DATE);</pre>
1903 * int m1 = cal.fieldDifference(date2, Calendar.MONTH);
1904 * int d1 = cal.fieldDifference(date2, Calendar.DATE);
1906 * int m2 = cal.fieldDifference(date1, Calendar.MONTH);
1907 * int d2 = cal.fieldDifference(date1, Calendar.DATE);</pre>
1911 * irregularities in the underlying calendar system (e.g., the
1912 * Gregorian calendar has a varying number of days per month).
1914 * @param when the date to compare this calendar's time to
1917 * this calendar's time and <code>when</code>, in terms of
1969 // of calendar computation.
2006 // Set calendar to end point
2019 calendar.setTimeZone(value.timeZone);
2024 * @return the time zone object associated with this calendar.
2029 return new TimeZone(calendar.getTimeZone());
2044 calendar.setLenient(lenient);
2053 return calendar.isLenient();
2113 // * <b>Note:</b>This option is effective only when this calendar is {@link #isLenient() lenient}.
2114 // * When the calendar is strict, such non-existing wall time will cause an exception.
2163 calendar.setFirstDayOfWeek(value);
2174 return calendar.getFirstDayOfWeek();
2188 calendar.setMinimalDaysInFirstWeek(value);
2202 return calendar.getMinimalDaysInFirstWeek();
2213 return calendar.getMinimum(getJDKField(field));
2224 return calendar.getMaximum(getJDKField(field));
2235 return calendar.getGreatestMinimum(getJDKField(field));
2246 return calendar.getLeastMaximum(getJDKField(field));
2257 * in this calendar system. If a transition occurs at midnight,
2290 // * calendar system. If getDayOfWeekType(dayOfWeek) == WEEKEND_ONSET return the time
2310 * {@icu} Returns true if the given date and time is in the weekend in this calendar
2312 * method changes the time this calendar is set to.
2322 calendar.setTime(date);
2327 * {@icu} Returns true if this Calendar's current date and time is in the weekend in
2328 * this calendar system.
2338 int dow = calendar.get(Calendar.DAY_OF_WEEK);
2355 return new Calendar((java.util.Calendar)calendar.clone());
2359 * Returns a string representation of this calendar. This method
2364 * @return a string representation of this calendar.
2368 return calendar.toString();
2372 * {@icu} Returns the number of fields defined by this calendar. Valid field
2384 * {@icu} Returns the current Calendar type. Note, in 3.0 this function will return
2385 * 'gregorian' in Calendar to emulate legacy behavior
2386 * @return type of calendar (gregorian, etc)
2391 String name = calendar.getClass().getSimpleName().toLowerCase(Locale.US);
2436 return java.util.Calendar.ERA;
2438 return java.util.Calendar.YEAR;
2440 return java.util.Calendar.MONTH;
2442 return java.util.Calendar.WEEK_OF_YEAR;
2444 return java.util.Calendar.WEEK_OF_MONTH;
2446 return java.util.Calendar.DATE;
2448 // return java.util.Calendar.DAY_OF_MONTH;
2450 return java.util.Calendar.DAY_OF_YEAR;
2452 return java.util.Calendar.DAY_OF_WEEK;
2454 return java.util.Calendar.DAY_OF_WEEK_IN_MONTH;
2456 return java.util.Calendar.AM_PM;
2458 return java.util.Calendar.HOUR;
2460 return java.util.Calendar.HOUR_OF_DAY;
2462 return java.util.Calendar.MINUTE;
2464 return java.util.Calendar.SECOND;
2466 return java.util.Calendar.MILLISECOND;
2468 return java.util.Calendar.ZONE_OFFSET;
2470 return java.util.Calendar.DST_OFFSET;
2478 // throw new UnsupportedOperationException("Calendar field type not supported by com.ibm.icu.base");
2481 throw new ArrayIndexOutOfBoundsException("Specified calendar field is out of range");