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

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29

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