/[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.9 by gnu_andrew, Wed Feb 16 01:11:42 2005 UTC revision 1.26.2.10 by gnu_andrew, Sun Mar 13 14:38:42 2005 UTC
# Line 145  public class GregorianCalendar extends C Line 145  public class GregorianCalendar extends C
145    
146    /**    /**
147     * The point at which the Gregorian calendar rules were used.     * The point at which the Gregorian calendar rules were used.
148     * This is locale dependent; the default for most catholic     * This may be changed by using setGregorianChange;
149     * countries is midnight (UTC) on October 5, 1582 (Julian),     * The default is midnight (UTC) on October 5, 1582 (Julian),
150     * or October 15, 1582 (Gregorian).     * or October 15, 1582 (Gregorian).
151     *     *
152     * @serial the changeover point from the Julian calendar     * @serial the changeover point from the Julian calendar
153     *         system to the Gregorian.     *         system to the Gregorian.
154     */     */
155    private long gregorianCutover;    private long gregorianCutover = (new Date((24 * 60 * 60 * 1000L) * (((1582 * (365 * 4
156                                                + 1)) / 4
157                                                + (java.util.Calendar.OCTOBER * (31
158                                                + 30 + 31 + 30 + 31) - 9) / 5 + 5)
159                                                - ((1970 * (365 * 4 + 1)) / 4 + 1
160                                                - 13)))).getTime();
161    
162    /**    /**
163     * For compatability with Sun's JDK.     * For compatability with Sun's JDK.
# Line 160  public class GregorianCalendar extends C Line 165  public class GregorianCalendar extends C
165    static final long serialVersionUID = -8125100834729963327L;    static final long serialVersionUID = -8125100834729963327L;
166    
167    /**    /**
    * The name of the resource bundle. Used only by getBundle()  
    */  
   private static final String bundleName = "gnu.java.locale.Calendar";  
   
   /**  
168     * Days in the epoch. Relative Jan 1, year '0' which is not a leap year.     * Days in the epoch. Relative Jan 1, year '0' which is not a leap year.
169     * (although there is no year zero, this does not matter.)     * (although there is no year zero, this does not matter.)
170     * This is consistent with the formula:     * This is consistent with the formula:
# Line 236  public class GregorianCalendar extends C Line 236  public class GregorianCalendar extends C
236    private GregorianCalendar(TimeZone zone, Locale locale, boolean unused)    private GregorianCalendar(TimeZone zone, Locale locale, boolean unused)
237    {    {
238      super(zone, locale);      super(zone, locale);
     ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale,  
                                                  ClassLoader  
                                                  .getSystemClassLoader());  
     gregorianCutover = ((Date) rb.getObject("gregorianCutOver")).getTime();  
239    }    }
240    
241    /**    /**
# Line 478  public class GregorianCalendar extends C Line 474  public class GregorianCalendar extends C
474    
475      if (isSet[AM_PM] && fields[AM_PM] != AM && fields[AM_PM] != PM)      if (isSet[AM_PM] && fields[AM_PM] != AM && fields[AM_PM] != PM)
476        throw new IllegalArgumentException("Illegal AM_PM.");        throw new IllegalArgumentException("Illegal AM_PM.");
477      if (isSet[HOUR] && (fields[HOUR] < 0 || fields[HOUR] > 12))      if (isSet[HOUR] && (fields[HOUR] < 0 || fields[HOUR] > 11))
478        throw new IllegalArgumentException("Illegal HOUR.");        throw new IllegalArgumentException("Illegal HOUR.");
479      if (isSet[HOUR_OF_DAY]      if (isSet[HOUR_OF_DAY]
480          && (fields[HOUR_OF_DAY] < 0 || fields[HOUR_OF_DAY] > 23))          && (fields[HOUR_OF_DAY] < 0 || fields[HOUR_OF_DAY] > 23))
# Line 564  public class GregorianCalendar extends C Line 560  public class GregorianCalendar extends C
560              // 3: YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK              // 3: YEAR + MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
561              if (isSet[DAY_OF_WEEK_IN_MONTH])              if (isSet[DAY_OF_WEEK_IN_MONTH])
562                {                {
563                    if (fields[DAY_OF_WEEK_IN_MONTH] < 0)
564                      {
565                        month++;
566                        first = getFirstDayOfMonth(year, month);
567                        day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH]);
568                      }
569                    else
570                      day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH] - 1);
571    
572                  int offs = fields[DAY_OF_WEEK] - first;                  int offs = fields[DAY_OF_WEEK] - first;
573                  if (offs < 0)                  if (offs < 0)
574                    offs += 7;                    offs += 7;
                 day = 1 + 7 * (fields[DAY_OF_WEEK_IN_MONTH] - 1);  
575                  day += offs;                  day += offs;
576                }                }
577              else              else
# Line 584  public class GregorianCalendar extends C Line 588  public class GregorianCalendar extends C
588    
589                  day = offs + 7 * (fields[WEEK_OF_MONTH] - 1);                  day = offs + 7 * (fields[WEEK_OF_MONTH] - 1);
590                  offs = fields[DAY_OF_WEEK] - getFirstDayOfWeek();                  offs = fields[DAY_OF_WEEK] - getFirstDayOfWeek();
591                  if (offs < 0)                  if (offs <= 0)
592                    offs += 7;                    offs += 7;
593                  day += offs;                  day += offs;
594                }                }
# Line 602  public class GregorianCalendar extends C Line 606  public class GregorianCalendar extends C
606        {        {
607          hour = fields[HOUR];          hour = fields[HOUR];
608          if (fields[AM_PM] == PM)          if (fields[AM_PM] == PM)
609            if (hour != 12) /* not Noon */            hour += 12;
             hour += 12;  
         /* Fix the problem of the status of 12:00 AM (midnight). */  
         if (fields[AM_PM] == AM && hour == 12)  
           hour = 0;  
610        }        }
611      else      else
612        hour = fields[HOUR_OF_DAY];        hour = fields[HOUR_OF_DAY];
# Line 858  public class GregorianCalendar extends C Line 858  public class GregorianCalendar extends C
858      int hourOfDay = millisInDay / (60 * 60 * 1000);      int hourOfDay = millisInDay / (60 * 60 * 1000);
859      fields[AM_PM] = (hourOfDay < 12) ? AM : PM;      fields[AM_PM] = (hourOfDay < 12) ? AM : PM;
860      int hour = hourOfDay % 12;      int hour = hourOfDay % 12;
861      fields[HOUR] = (hour == 0) ? 12 : hour;      fields[HOUR] = hour;
862      fields[HOUR_OF_DAY] = hourOfDay;      fields[HOUR_OF_DAY] = hourOfDay;
863      millisInDay %= (60 * 60 * 1000);      millisInDay %= (60 * 60 * 1000);
864      fields[MINUTE] = millisInDay / (60 * 1000);      fields[MINUTE] = millisInDay / (60 * 1000);
# Line 926  public class GregorianCalendar extends C Line 926  public class GregorianCalendar extends C
926          isTimeSet = false;          isTimeSet = false;
927          int maxDay = getActualMaximum(DAY_OF_MONTH);          int maxDay = getActualMaximum(DAY_OF_MONTH);
928          if (fields[DAY_OF_MONTH] > maxDay)          if (fields[DAY_OF_MONTH] > maxDay)
929            {            fields[DAY_OF_MONTH] = maxDay;
             fields[DAY_OF_MONTH] = maxDay;  
             isTimeSet = false;  
           }  
930          break;          break;
931        case DAY_OF_MONTH:        case DAY_OF_MONTH:
932        case DAY_OF_YEAR:        case DAY_OF_YEAR:

Legend:
Removed from v.1.26.2.9  
changed lines
  Added in v.1.26.2.10

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