/[classpath]/classpath/java/util/GregorianCalendar.java
ViewVC logotype

Diff of /classpath/java/util/GregorianCalendar.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.26.2.1 by gnu_andrew, Sat Jan 15 17:02:16 2005 UTC revision 1.26.2.2 by gnu_andrew, Sun Jan 16 02:14:48 2005 UTC
# Line 40  exception statement from your version. * Line 40  exception statement from your version. *
40  package java.util;  package java.util;
41    
42  /**  /**
43     * <p>
44   * This class represents the Gregorian calendar, that is used in most   * This class represents the Gregorian calendar, that is used in most
45   * countries all over the world.  It does also handle the Julian calendar   * countries all over the world.  It does also handle the Julian calendar
46   * for dates smaller than the date of the change to the Gregorian calendar.   * for dates smaller than the date of the change to the Gregorian calendar.
  * This change date is different from country to country, you can set it with  
  * <code>setGregorianChange</code>  
  *  
47   * The Gregorian calendar differs from the Julian calendar by a different   * The Gregorian calendar differs from the Julian calendar by a different
48   * leap year rule (no leap year every 100 years, except if year is divisible   * leap year rule (no leap year every 100 years, except if year is divisible
49   * by 400).  The non existing days that were omited when the change took   * by 400).  
50   * place are interpreted as gregorian date   * </p>
51   *   * <p>
52   * There are to eras available for the Gregorian calendar, namely BC and AD.   * This change date is different from country to country, and can be changed with
53     * <code>setGregorianChange</code>.  The first countries to adopt the Gregorian
54     * calendar did so on the 15th of October, 1582.  This date followed October
55     * the 4th, 1582 in the Julian calendar system.  The non-existant days that were
56     * omitted when the change took place are interpreted as Gregorian dates.
57     * </p>
58     * <p>
59     * Prior to the changeover date, New Year's Day occurred on the 25th of March.
60     * However, this class always takes New Year's Day as being the 1st of January.
61     * Client code should manually adapt the year value, if required, for dates
62     * between January the 1st and March the 24th in years prior to the changeover.
63     * </p>
64     * <p>
65     * Any date infinitely forwards or backwards in time can be represented by
66     * this class.  A <em>proleptic</em> calendar system is used, which allows
67     * future dates to be created via the existing rules.  This allows meaningful
68     * and consistent dates to be produced for all years.  However, dates are only
69     * historically accurate following March the 1st, 4AD when the Julian calendar
70     * system was adopted.  Prior to this, leap year rules were applied erraticly.
71     * </p>
72     * <p>
73     * There are two eras available for the Gregorian calendar, namely BC and AD.
74     * </p>
75     * <p>
76     * Weeks are defined as a period of seven days, beginning on the first day
77     * of the week, as returned by <code>getFirstDayOfWeek()</code>, and ending
78     * on the day prior to this.
79     * </p>
80     * <p>
81     * The weeks of the year are numbered from 1 to a possible 53.  The first week
82     * of the year is defined as the first week that contains at least the minimum
83     * number of days of the first week in the new year (retrieved via
84     * <code>getMinimalDaysInFirstWeek()</code>).  All weeks after this are numbered
85     * from 2 onwards.
86     * </p>
87     * <p>
88     * For example, take the year 2004.  It began on a Thursday.  The first week
89     * of 2004 depends both on where a week begins and how long it must minimally
90     * last.  Let's say that the week begins on a Monday and must have a minimum
91     * of 5 days.  In this case, the first week begins on Monday, the 5th of January.
92     * The first 4 days (Thursday to Sunday) are not eligible, as they are too few
93     * to make up the minimum number of days of the first week which must be in
94     * the new year.  If the minimum was lowered to 4 days, then the first week
95     * would instead begin on Monday, the 29th of December, 2003.  This first week
96     * has 4 of its days in the new year, and is now eligible.
97     * </p>
98     * <p>
99     * The weeks of the month are numbered from 0 to a possible 6.  The first week
100     * of the month (numbered 1) is a set of days, prior to the first day of the week,
101     * which number at least the minimum number of days in a week.  Unlike the first
102     * week of the year, the first week of the month only uses days from that particular
103     * month.  As a consequence, it may have a variable number of days (from the minimum
104     * number required up to a full week of 7) and it need not start on the first day of
105     * the week.  It must, however, be following by the first day of the week, as this
106     * marks the beginning of week 2.  Any days of the month which occur prior to the
107     * first week (because the first day of the week occurs before the minimum number
108     * of days is met) are seen as week 0.
109     * </p>
110     * <p>
111     * Again, we will take the example of the year 2004 to demonstrate this.  September
112     * 2004 begins on a Wednesday.  Taking our first day of the week as Monday, and the
113     * minimum length of the first week as 6, we find that week 1 runs from Monday,
114     * the 6th of September to Sunday the 12th.  Prior to the 6th, there are only
115     * 5 days (Wednesday through to Sunday).  This is too small a number to meet the
116     * minimum, so these are classed as being days in week 0.  Week 2 begins on the
117     * 13th, and so on.  This changes if we reduce the minimum to 5.  In this case,
118     * week 1 is a truncated week from Wednesday the 1st to Sunday the 5th, and week
119     * 0 doesn't exist.  The first seven day week is week 2, starting on the 6th.
120     * </p>
121     * <p>
122     * On using the <code>clear()</code> method, the Gregorian calendar returns
123     * to its default value of the 1st of January, 1970 AD 00:00:00 (the epoch).
124     * The day of the week is set to the correct day for that particular time.
125     * The day is also the first of the month, and the date is in week 0.
126     * </p>
127   *   *
128   * @see Calendar   * @see Calendar
129   * @see TimeZone   * @see TimeZone
130     * @see Calendar#getFirstDayOfWeek()
131     * @see Calendar#getMinimalDaysInFirstWeek()
132   */   */
133  public class GregorianCalendar extends Calendar  public class GregorianCalendar extends Calendar
134  {  {
135    /**    /**
136     * Constant representing the era BC (before Christ).     * Constant representing the era BC (Before Christ).
137     */     */
138    public static final int BC = 0;    public static final int BC = 0;
139        
# Line 73  public class GregorianCalendar extends C Line 147  public class GregorianCalendar extends C
147     * This is locale dependent; the default for most catholic     * This is locale dependent; the default for most catholic
148     * countries is midnight (UTC) on October 5, 1582 (Julian),     * countries is midnight (UTC) on October 5, 1582 (Julian),
149     * or October 15, 1582 (Gregorian).     * or October 15, 1582 (Gregorian).
150       *
151       * @serial the changeover point from the Julian calendar
152       *         system to the Gregorian.
153     */     */
154    private long gregorianCutover;    private long gregorianCutover;
155    
156      /**
157       * For compatability with Sun's JDK.
158       */
159    static final long serialVersionUID = -8125100834729963327L;    static final long serialVersionUID = -8125100834729963327L;
160    
161    /**    /**
# Line 84  public class GregorianCalendar extends C Line 164  public class GregorianCalendar extends C
164    private static final String bundleName = "gnu.java.locale.Calendar";    private static final String bundleName = "gnu.java.locale.Calendar";
165    
166    /**    /**
167     * get resource bundle:     * Retrieves the resource bundle.  The resources should be loaded
168     * The resources should be loaded via this method only. Iff an application     * via this method only. Iff an application uses this method, the
169     * uses this method, the resourcebundle is required. --Fridi.     * resourcebundle is required.
170       *
171       * @param locale the locale in use for this calendar.
172       * @return A resource bundle for the calendar for the specified locale.
173     */     */
174    private static ResourceBundle getBundle(Locale locale)    private static ResourceBundle getBundle(Locale locale)
175    {    {
# Line 105  public class GregorianCalendar extends C Line 188  public class GregorianCalendar extends C
188        
189    /**    /**
190     * Constructs a new GregorianCalender representing the current     * Constructs a new GregorianCalender representing the current
191     * time, using the specified time zone and the default locale.       * time, using the specified time zone and the default locale.
192       *
193     * @param zone a time zone.     * @param zone a time zone.
194     */     */
195    public GregorianCalendar(TimeZone zone)    public GregorianCalendar(TimeZone zone)
# Line 115  public class GregorianCalendar extends C Line 199  public class GregorianCalendar extends C
199        
200    /**    /**
201     * Constructs a new GregorianCalender representing the current     * Constructs a new GregorianCalender representing the current
202     * time, using the default time zone and the specified locale.       * time, using the default time zone and the specified locale.
203       *  
204     * @param locale a locale.     * @param locale a locale.
205     */     */
206    public GregorianCalendar(Locale locale)    public GregorianCalendar(Locale locale)
# Line 126  public class GregorianCalendar extends C Line 211  public class GregorianCalendar extends C
211    /**    /**
212     * Constructs a new GregorianCalender representing the current     * Constructs a new GregorianCalender representing the current
213     * time with the given time zone and the given locale.     * time with the given time zone and the given locale.
214       *
215     * @param zone a time zone.       * @param zone a time zone.  
216     * @param locale a locale.       * @param locale a locale.  
217     */     */
# Line 152  public class GregorianCalendar extends C Line 238  public class GregorianCalendar extends C
238    /**    /**
239     * Constructs a new GregorianCalendar representing midnight on the     * Constructs a new GregorianCalendar representing midnight on the
240     * given date with the default time zone and locale.     * given date with the default time zone and locale.
241       *
242     * @param year corresponds to the YEAR time field.     * @param year corresponds to the YEAR time field.
243     * @param month corresponds to the MONTH time field.     * @param month corresponds to the MONTH time field.
244     * @param day corresponds to the DAY time field.     * @param day corresponds to the DAY time field.
# Line 165  public class GregorianCalendar extends C Line 252  public class GregorianCalendar extends C
252    /**    /**
253     * Constructs a new GregorianCalendar representing midnight on the     * Constructs a new GregorianCalendar representing midnight on the
254     * given date with the default time zone and locale.     * given date with the default time zone and locale.
255       *
256     * @param year corresponds to the YEAR time field.     * @param year corresponds to the YEAR time field.
257     * @param month corresponds to the MONTH time field.     * @param month corresponds to the MONTH time field.
258     * @param day corresponds to the DAY time field.     * @param day corresponds to the DAY time field.
# Line 180  public class GregorianCalendar extends C Line 268  public class GregorianCalendar extends C
268    /**    /**
269     * Constructs a new GregorianCalendar representing midnight on the     * Constructs a new GregorianCalendar representing midnight on the
270     * given date with the default time zone and locale.     * given date with the default time zone and locale.
271       *
272     * @param year corresponds to the YEAR time field.     * @param year corresponds to the YEAR time field.
273     * @param month corresponds to the MONTH time field.     * @param month corresponds to the MONTH time field.
274     * @param day corresponds to the DAY time field.     * @param day corresponds to the DAY time field.
# Line 199  public class GregorianCalendar extends C Line 288  public class GregorianCalendar extends C
288     * You can use <code>new Date(Long.MAX_VALUE)</code> to use a pure     * You can use <code>new Date(Long.MAX_VALUE)</code> to use a pure
289     * Julian calendar, or <code>Long.MIN_VALUE</code> for a pure Gregorian     * Julian calendar, or <code>Long.MIN_VALUE</code> for a pure Gregorian
290     * calendar.     * calendar.
291       *
292     * @param date the date of the change.     * @param date the date of the change.
293     */     */
294    public void setGregorianChange(Date date)    public void setGregorianChange(Date date)
# Line 208  public class GregorianCalendar extends C Line 298  public class GregorianCalendar extends C
298    
299    /**    /**
300     * Gets the date of the switch from Julian dates to Gregorian dates.     * Gets the date of the switch from Julian dates to Gregorian dates.
301       *
302     * @return the date of the change.     * @return the date of the change.
303     */     */
304    public final Date getGregorianChange()    public final Date getGregorianChange()
# Line 216  public class GregorianCalendar extends C Line 307  public class GregorianCalendar extends C
307    }    }
308    
309    /**    /**
310       * <p>
311     * Determines if the given year is a leap year.  The result is     * Determines if the given year is a leap year.  The result is
312     * undefined if the gregorian change took place in 1800, so that     * undefined if the Gregorian change took place in 1800, so that
313     * the end of february is skiped and you give that year     * the end of February is skipped, and that year is specified.
314     * (well...).<br>     * (well...).
315     *     * </p>
316     * The year should be positive and you can't give an ERA.  But     * <p>
317     * remember that before 4 BC there wasn't a consistent leap year     * To specify a year in the BC era, use a negative value calculated
318     * rule, so who cares.     * as 1 - y, where y is the required year in BC.  So, 1 BC is 0,
319       * 2 BC is -1, 3 BC is -2, etc.
320       * </p>
321     *     *
322     * @param year a year use nonnegative value for BC.     * @param year a year (use a negative value for BC).
323     * @return true, if the given year is a leap year, false otherwise.  */     * @return true, if the given year is a leap year, false otherwise.  
324       */
325    public boolean isLeapYear(int year)    public boolean isLeapYear(int year)
326    {    {
327      if ((year & 3) != 0)      if ((year & 3) != 0)
# Line 256  public class GregorianCalendar extends C Line 351  public class GregorianCalendar extends C
351     * @param year the year of the date.     * @param year the year of the date.
352     * @param dayOfYear the day of year of the date; 1 based.     * @param dayOfYear the day of year of the date; 1 based.
353     * @param millis the millisecond in that day.     * @param millis the millisecond in that day.
354     * @return the days since the epoch, may be negative.  */     * @return the days since the epoch, may be negative.  
355       */
356    private long getLinearTime(int year, int dayOfYear, int millis)    private long getLinearTime(int year, int dayOfYear, int millis)
357    {    {
358      // The 13 is the number of days, that were omitted in the Gregorian      // The 13 is the number of days, that were omitted in the Gregorian
359      // Calender until the epoch.      // Calendar until the epoch.
360      // We shift right by 2 instead of dividing by 4, to get correct      // We shift right by 2 instead of dividing by 4, to get correct
361      // results for negative years (and this is even more efficient).      // results for negative years (and this is even more efficient).
362      int julianDay = ((year * (365 * 4 + 1)) >> 2) + dayOfYear -      int julianDay = ((year * (365 * 4 + 1)) >> 2) + dayOfYear -
# Line 288  public class GregorianCalendar extends C Line 384  public class GregorianCalendar extends C
384      return time;      return time;
385    }    }
386    
387      /**
388       * Retrieves the day of the week corresponding to the specified
389       * day of the specified year.
390       *
391       * @param year the year in which the dayOfYear occurs.
392       * @param dayOfYear the day of the year (an integer between 0 and
393       *        and 366)
394       */
395    private int getWeekDay(int year, int dayOfYear)    private int getWeekDay(int year, int dayOfYear)
396    {    {
397      int day =      int day =
# Line 301  public class GregorianCalendar extends C Line 405  public class GregorianCalendar extends C
405    }    }
406    
407    /**    /**
408       * <p>
409     * Calculate the dayOfYear from the fields array.       * Calculate the dayOfYear from the fields array.  
410     * The relativeDays is used, to account for weeks that begin before     * The relativeDays is used, to account for weeks that begin before
411     * the gregorian change and end after it.<br>     * the Gregorian change and end after it.
412     *     * </p>
413     * We return two values, the first is used to determine, if we     * <p>
414     * should use Gregorian calendar or Julian calendar, in case of     * We return two values.  The first is used to determine, if we
415     * the change year, the second is a relative day after the given     * should use the Gregorian calendar or the Julian calendar, in order
416       * to handle the change year. The second is a relative day after the given
417     * day.  This is necessary for week calculation in the year in     * day.  This is necessary for week calculation in the year in
418     * which gregorian change occurs. <br>     * which the Gregorian change occurs.
419     *     * </p>
420       *
421     * @param year the year, negative for BC.     * @param year the year, negative for BC.
422     * @return an array of two int values, the first containing a reference     * @return an array of two integer values, the first containing a reference
423     * day of current year, the second a relative count since this reference     * day in the current year, the second a relative count since this reference
424     * day.  */     * day.  
425       */
426    private int[] getDayOfYear(int year)    private int[] getDayOfYear(int year)
427    {    {
428      if (isSet[MONTH])      if (isSet[MONTH])
# Line 399  public class GregorianCalendar extends C Line 507  public class GregorianCalendar extends C
507    /**    /**
508     * Converts the time field values (<code>fields</code>) to     * Converts the time field values (<code>fields</code>) to
509     * milliseconds since the epoch UTC (<code>time</code>).     * milliseconds since the epoch UTC (<code>time</code>).
510       *
511       * @throws IllegalArgumentException if any calendar fields
512       *         are invalid.
513     */     */
514    protected synchronized void computeTime()    protected synchronized void computeTime()
515    {    {
# Line 493  public class GregorianCalendar extends C Line 604  public class GregorianCalendar extends C
604    }    }
605    
606    /**    /**
607       * <p>
608     * Determines if the given year is a leap year.       * Determines if the given year is a leap year.  
609       * </p>
610       * <p>
611       * To specify a year in the BC era, use a negative value calculated
612       * as 1 - y, where y is the required year in BC.  So, 1 BC is 0,
613       * 2 BC is -1, 3 BC is -2, etc.
614       * </p>
615     *     *
616     * The year should be positive and you can't give an ERA.  But     * @param year a year (use a negative value for BC).
617     * remember that before 4 BC there wasn't a consistent leap year     * @param gregorian if true, use the gregorian leap year rule.
618     * rule, so who cares.     * @return true, if the given year is a leap year, false otherwise.  
619     *     */
    * @param year a year use nonnegative value for BC.  
    * @param gregorian if true, use gregorian leap year rule.  
    * @return true, if the given year is a leap year, false otherwise.  */  
620    private boolean isLeapYear(int year, boolean gregorian)    private boolean isLeapYear(int year, boolean gregorian)
621    {    {
622      if ((year & 3) != 0)      if ((year & 3) != 0)
# Line 523  public class GregorianCalendar extends C Line 638  public class GregorianCalendar extends C
638     *     *
639     * @param year the year of the date.     * @param year the year of the date.
640     * @param dayOfYear the day of year of the date; 1 based.     * @param dayOfYear the day of year of the date; 1 based.
641     * @param gregorian True, if we should use Gregorian rules.     * @param gregorian <code>true</code>, if we should use the Gregorian rules.
642     * @return the days since the epoch, may be negative.  */     * @return the days since the epoch, may be negative.  
643       */
644    private long getLinearDay(int year, int dayOfYear, boolean gregorian)    private long getLinearDay(int year, int dayOfYear, boolean gregorian)
645    {    {
646      // The 13 is the number of days, that were omitted in the Gregorian      // The 13 is the number of days, that were omitted in the Gregorian
# Line 557  public class GregorianCalendar extends C Line 673  public class GregorianCalendar extends C
673     * Converts the given linear day into era, year, month,     * Converts the given linear day into era, year, month,
674     * day_of_year, day_of_month, day_of_week, and writes the result     * day_of_year, day_of_month, day_of_week, and writes the result
675     * into the fields array.     * into the fields array.
676       *
677     * @param day the linear day.       * @param day the linear day.  
678       * @param gregorian true, if we should use Gregorian rules.
679     */     */
680    private void calculateDay(int[] fields, long day, boolean gregorian)    private void calculateDay(int[] fields, long day, boolean gregorian)
681    {    {
# Line 616  public class GregorianCalendar extends C Line 734  public class GregorianCalendar extends C
734    /**    /**
735     * Converts the milliseconds since the epoch UTC     * Converts the milliseconds since the epoch UTC
736     * (<code>time</code>) to time fields     * (<code>time</code>) to time fields
737     * (<code>fields</code>).     * (<code>fields</code>).
738     */     */
739    protected synchronized void computeFields()    protected synchronized void computeFields()
740    {    {
# Line 688  public class GregorianCalendar extends C Line 806  public class GregorianCalendar extends C
806    }    }
807    
808    /**    /**
809     * Compares the given calender with this.       * Compares the given calendar with this.  An object, o, is
810       * equivalent to this if it is also a <code>GregorianCalendar</code>
811       * with the same time since the epoch under the same conditions
812       * (same change date and same time zone).
813       *  
814     * @param o the object to that we should compare.     * @param o the object to that we should compare.
815     * @return true, if the given object is a calendar, that represents     * @return true, if the given object is a calendar, that represents
816     * the same time (but doesn't necessary have the same fields).     * the same time (but doesn't necessarily have the same fields).
817     * @XXX Should we check if time zones, locale, cutover etc. are equal?     * @throws IllegalArgumentException if one of the fields
818       *         <code>ZONE_OFFSET</code> or <code>DST_OFFSET</code> is
819       *         specified, if an unknown field is specified or if one
820       *         of the calendar fields receives an illegal value when
821       *         leniancy is not enabled.
822     */     */
823    public boolean equals(Object o)    public boolean equals(Object o)
824    {    {
# Line 735  public class GregorianCalendar extends C Line 861  public class GregorianCalendar extends C
861     * Adds the specified amount of time to the given time field.  The     * Adds the specified amount of time to the given time field.  The
862     * amount may be negative to subtract the time.  If the field overflows     * amount may be negative to subtract the time.  If the field overflows
863     * it does what you expect: Jan, 25 + 10 Days is Feb, 4.     * it does what you expect: Jan, 25 + 10 Days is Feb, 4.
864     * @param field the time field. One of the time field constants.     * @param field one of the time field constants.
865     * @param amount the amount of time.     * @param amount the amount of time to add.
866     * @exception IllegalArgumentException if <code>field</code> is     * @exception IllegalArgumentException if <code>field</code> is
867     *   <code>ZONE_OFFSET</code>, <code>DST_OFFSET</code>, or invalid; or     *   <code>ZONE_OFFSET</code>, <code>DST_OFFSET</code>, or invalid; or
868     *   if <code>amount</code> contains an out-of-range value and the calendar     *   if <code>amount</code> contains an out-of-range value and the calendar
# Line 837  public class GregorianCalendar extends C Line 963  public class GregorianCalendar extends C
963     *     *
964     * @param field the time field. One of the time field constants.     * @param field the time field. One of the time field constants.
965     * @param up the direction, true for up, false for down.     * @param up the direction, true for up, false for down.
966       * @throws IllegalArgumentException if one of the fields
967       *         <code>ZONE_OFFSET</code> or <code>DST_OFFSET</code> is
968       *         specified, if an unknown field is specified or if one
969       *         of the calendar fields receives an illegal value when
970       *         leniancy is not enabled.
971     */     */
972    public void roll(int field, boolean up)    public void roll(int field, boolean up)
973    {    {
974      roll(field, up ? 1 : -1);      roll(field, up ? 1 : -1);
975    }    }
976    
977      /**
978       * Checks that the fields are still within their legal bounds,
979       * following use of the <code>roll()</code> method.
980       *
981       * @param field the field to check.
982       * @param delta multipler for alterations to the <code>time</code>.
983       * @see #roll(int, boolean)
984       * @see #roll(int, int)
985       */
986    private void cleanUpAfterRoll(int field, int delta)    private void cleanUpAfterRoll(int field, int delta)
987    {    {
988      switch (field)      switch (field)
# Line 940  public class GregorianCalendar extends C Line 1080  public class GregorianCalendar extends C
1080     *     *
1081     * @param field the time field. One of the time field constants.     * @param field the time field. One of the time field constants.
1082     * @param amount the amount by which we should roll.     * @param amount the amount by which we should roll.
1083       * @throws IllegalArgumentException if one of the fields
1084       *         <code>ZONE_OFFSET</code> or <code>DST_OFFSET</code> is
1085       *         specified, if an unknown field is specified or if one
1086       *         of the calendar fields receives an illegal value when
1087       *         leniancy is not enabled.
1088     */     */
1089    public void roll(int field, int amount)    public void roll(int field, int amount)
1090    {    {
# Line 964  public class GregorianCalendar extends C Line 1109  public class GregorianCalendar extends C
1109      cleanUpAfterRoll(field, newval - oldval);      cleanUpAfterRoll(field, newval - oldval);
1110    }    }
1111    
1112      /**
1113       * The minimum values for the calendar fields.
1114       */
1115    private static final int[] minimums =    private static final int[] minimums =
1116        { BC,       1,  0,  0, 1,  1,   1,   SUNDAY, 1,        { BC,       1,  0,  0, 1,  1,   1,   SUNDAY, 1,
1117          AM,  1,  0,  1,  1,   1, -(12*60*60*1000),               0 };          AM,  1,  0,  1,  1,   1, -(12*60*60*1000),               0 };
1118    
1119      /**
1120       * The maximum values for the calendar fields.
1121       */
1122    private static final int[] maximums =    private static final int[] maximums =
1123        { AD, 5000000, 11, 53, 5, 31, 366, SATURDAY, 5,        { AD, 5000000, 11, 53, 5, 31, 366, SATURDAY, 5,
1124          PM, 12, 23, 59, 59, 999, +(12*60*60*1000), (12*60*60*1000) };          PM, 12, 23, 59, 59, 999, +(12*60*60*1000), (12*60*60*1000) };
1125    
1126    /**    /**
1127     * Gets the smallest value that is allowed for the specified field.     * Gets the smallest value that is allowed for the specified field.
1128     * @param field the time field. One of the time field constants.     *
1129     * @return the smallest value.     * @param field one of the time field constants.
1130       * @return the smallest value for the specified field.
1131     */     */
1132    public int getMinimum(int field)    public int getMinimum(int field)
1133    {    {
# Line 984  public class GregorianCalendar extends C Line 1136  public class GregorianCalendar extends C
1136    
1137    /**    /**
1138     * Gets the biggest value that is allowed for the specified field.     * Gets the biggest value that is allowed for the specified field.
1139     * @param field the time field. One of the time field constants.     *
1140       * @param field one of the time field constants.
1141     * @return the biggest value.     * @return the biggest value.
1142     */     */
1143    public int getMaximum(int field)    public int getMaximum(int field)
# Line 995  public class GregorianCalendar extends C Line 1148  public class GregorianCalendar extends C
1148    
1149    /**    /**
1150     * Gets the greatest minimum value that is allowed for the specified field.     * Gets the greatest minimum value that is allowed for the specified field.
1151       * This is the largest value returned by the <code>getActualMinimum(int)</code>
1152       * method.
1153       *
1154     * @param field the time field. One of the time field constants.     * @param field the time field. One of the time field constants.
1155     * @return the greatest minimum value.     * @return the greatest minimum value.
1156       * @see #getActualMinimum(int)
1157     */     */
1158    public int getGreatestMinimum(int field)    public int getGreatestMinimum(int field)
1159    {    {
# Line 1007  public class GregorianCalendar extends C Line 1164  public class GregorianCalendar extends C
1164    
1165    /**    /**
1166     * Gets the smallest maximum value that is allowed for the     * Gets the smallest maximum value that is allowed for the
1167     * specified field.  For example this is 28 for DAY_OF_MONTH.     * specified field.  This is the smallest value returned
1168       * by the <code>getActualMaximum(int)</code>.  For example,
1169       * this is 28 for DAY_OF_MONTH (as all months have at least
1170       * 28 days).
1171       *
1172     * @param field the time field. One of the time field constants.     * @param field the time field. One of the time field constants.
1173     * @return the least maximum value.       * @return the least maximum value.  
1174     * @since jdk1.2     * @see #getActualMaximum(int)
1175       * @since 1.2
1176     */     */
1177    public int getLeastMaximum(int field)    public int getLeastMaximum(int field)
1178    {    {
# Line 1034  public class GregorianCalendar extends C Line 1196  public class GregorianCalendar extends C
1196     * Gets the actual minimum value that is allowed for the specified field.     * Gets the actual minimum value that is allowed for the specified field.
1197     * This value is dependent on the values of the other fields.  Note that     * This value is dependent on the values of the other fields.  Note that
1198     * this calls <code>complete()</code> if not enough fields are set.  This     * this calls <code>complete()</code> if not enough fields are set.  This
1199     * can have ugly side effects.     * can have ugly side effects.  The value given depends on the current
1200       * time used by this instance.
1201       *
1202     * @param field the time field. One of the time field constants.     * @param field the time field. One of the time field constants.
1203     * @return the actual minimum value.     * @return the actual minimum value.
1204     * @since jdk1.2     * @since 1.2
1205     */     */
1206    public int getActualMinimum(int field)    public int getActualMinimum(int field)
1207    {    {
# Line 1062  public class GregorianCalendar extends C Line 1226  public class GregorianCalendar extends C
1226     * Gets the actual maximum value that is allowed for the specified field.     * Gets the actual maximum value that is allowed for the specified field.
1227     * This value is dependent on the values of the other fields.  Note that     * This value is dependent on the values of the other fields.  Note that
1228     * this calls <code>complete()</code> if not enough fields are set.  This     * this calls <code>complete()</code> if not enough fields are set.  This
1229     * can have ugly side effects.     * can have ugly side effects.  The value given depends on the current time
1230       * used by this instance; thus, leap years have a maximum day of month value of
1231       * 29, rather than 28.
1232       *
1233     * @param field the time field. One of the time field constants.     * @param field the time field. One of the time field constants.
1234     * @return the actual maximum value.       * @return the actual maximum value.  
1235     */     */
# Line 1085  public class GregorianCalendar extends C Line 1252  public class GregorianCalendar extends C
1252    
1253            int minimalDays = getMinimalDaysInFirstWeek();            int minimalDays = getMinimalDaysInFirstWeek();
1254            int firstWeekday = getWeekDay(year, minimalDays);            int firstWeekday = getWeekDay(year, minimalDays);
1255              /*
1256               * Is there a set of days at the beginning of the year, before the
1257               * first day of the week, equal to or greater than the minimum number
1258               * of days required in the first week?
1259               */
1260            if (minimalDays - (7 + firstWeekday - getFirstDayOfWeek()) % 7 < 1)            if (minimalDays - (7 + firstWeekday - getFirstDayOfWeek()) % 7 < 1)
1261              return week + 1;              return week + 1; /* Add week 1: firstWeekday through to firstDayOfWeek */
1262          }          }
1263          case DAY_OF_MONTH:          case DAY_OF_MONTH:
1264          {          {
# Line 1133  public class GregorianCalendar extends C Line 1305  public class GregorianCalendar extends C
1305          return maximums[field];          return maximums[field];
1306        }        }
1307    }    }
1308    
1309    
1310  }  }

Legend:
Removed from v.1.26.2.1  
changed lines
  Added in v.1.26.2.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26