⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpletimezone.java

📁 this gcc-g++-3.3.1.tar.gz is a source file of gcc, you can learn more about gcc through this codes f
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* java.util.SimpleTimeZone   Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.util;import java.text.DateFormatSymbols;/** * This class represents a simple time zone offset and handles * daylight savings.  It can only handle one daylight savings rule, so * it can't represent historical changes. * * This object is tightly bound to the Gregorian calendar.  It assumes * a regular seven days week, and the month lengths are that of the * Gregorian Calendar.  It can only handle daylight savings for years * lying in the AD era. * * @see Calendar * @see GregorianCalender  * @author Jochen Hoenicke */public class SimpleTimeZone extends TimeZone{  /**   * The raw time zone offset in milliseconds to GMT, ignoring   * daylight savings.     * @serial   */  private int rawOffset;  /**   * True, if this timezone uses daylight savings, false otherwise.   * @serial   */  private boolean useDaylight;  /**   * The daylight savings offset.  This is a positive offset in   * milliseconds with respect to standard time.  Typically this   * is one hour, but for some time zones this may be half an our.   * @serial   * @since JDK1.1.4   */  private int dstSavings = 60 * 60 * 1000;  /**   * The first year, in which daylight savings rules applies.     * @serial   */  private int startYear;  private static final int DOM_MODE = 1;  private static final int DOW_IN_MONTH_MODE = 2;  private static final int DOW_GE_DOM_MODE = 3;  private static final int DOW_LE_DOM_MODE = 4;  /**   * The mode of the start rule. This takes one of the following values:   * <dl>   * <dt>DOM_MODE (1)</dt>   * <dd> startDay contains the day in month of the start date,   * startDayOfWeek is unused. </dd>   * <dt>DOW_IN_MONTH_MODE (2)</dt>   * <dd> The startDay gives the day of week in month, and   * startDayOfWeek the day of week.  For example startDay=2 and   * startDayOfWeek=Calender.SUNDAY specifies that the change is on   * the second sunday in that month.  You must make sure, that this   * day always exists (ie. don't specify the 5th sunday).   * </dd>   * <dt>DOW_GE_DOM_MODE (3)</dt>   * <dd> The start is on the first startDayOfWeek on or after   * startDay.  For example startDay=13 and   * startDayOfWeek=Calendar.FRIDAY specifies that the daylight   * savings start on the first FRIDAY on or after the 13th of that   * Month. Make sure that the change is always in the given month, or   * the result is undefined.   * </dd>   * <dt>DOW_LE_DOM_MONTH (4)</dt>   * <dd> The start is on the first startDayOfWeek on or before the   * startDay.  Make sure that the change is always in the given   * month, or the result is undefined.   </dd>   * </dl>   * @serial */  private int startMode;  /**   * The month in which daylight savings start.  This is one of the   * constants Calendar.JANUARY, ..., Calendar.DECEMBER.     * @serial   */  private int startMonth;  /**   * This variable can have different meanings.  See startMode for details   * @see #startMode;   * @serial   */     private int startDay;    /**   * This variable specifies the day of week the change takes place.  If    * startMode == DOM_MODE, this is undefined.   * @serial   * @see #startMode;   */     private int startDayOfWeek;    /**   * This variable specifies the time of change to daylight savings.   * This time is given in milliseconds after midnight local   * standard time.     * @serial   */  private int startTime;     /**   * The month in which daylight savings ends.  This is one of the   * constants Calendar.JANUARY, ..., Calendar.DECEMBER.     * @serial   */     private int endMonth;  /**   * This variable gives the mode for the end of daylight savings rule.   * It can take the same values as startMode.   * @serial   * @see #startMode   */     private int endMode;  /**   * This variable can have different meanings.  See startMode for details   * @serial   * @see #startMode;   */  private int endDay;    /**   * This variable specifies the day of week the change takes place.  If    * endMode == DOM_MODE, this is undefined.   * @serial   * @see #startMode;   */  private int endDayOfWeek;    /**   * This variable specifies the time of change back to standard time.   * This time is given in milliseconds after midnight local   * standard time.     * @serial   */  private int endTime;  /**   * This variable points to a deprecated array from JDK 1.1.  It is   * ignored in JDK 1.2 but streamed out for compatibility with JDK 1.1.   * The array contains the lengths of the months in the year and is   * assigned from a private static final field to avoid allocating   * the array for every instance of the object.   * Note that static final fields are not serialized.   * @serial   */  private byte[] monthLength = monthArr;  private static final byte[] monthArr =    {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};  /**   * The version of the serialized data on the stream.   * <dl>   * <dt>0 or not present on stream</dt>   * <dd> JDK 1.1.3 or earlier, only provides this fields:   * rawOffset, startDay, startDayOfWeek, startMonth, startTime,   * startYear, endDay, endDayOfWeek, endMonth, endTime   * </dd>   * <dd> JDK 1.1.4 or later. This includes three new fields, namely   * startMode, endMode and dstSavings.  And there is a optional section   * as described in writeObject.   * </dd>   *   * XXX - JDK 1.2 Beta 4 docu states 1.1.4, but my 1.1.5 has the old   * version.   *   * When streaming out this class it is always written in the latest   * version.   * @serial   * @since JDK1.1.4    */  private int serialVersionOnStream = 1;  private static final long serialVersionUID = -403250971215465050L;  /**   * Create a <code>SimpleTimeZone</code> with the given time offset   * from GMT and without daylight savings.     * @param rawOffset the time offset from GMT in milliseconds.   * @param id The identifier of this time zone.     */  public SimpleTimeZone(int rawOffset, String id)  {    this.rawOffset = rawOffset;    setID(id);    useDaylight = false;    startYear = 0;  }  /**   * Create a <code>SimpleTimeZone</code> with the given time offset   * from GMT and with daylight savings.  The start/end parameters   * can have different meaning (replace WEEKDAY with a real day of   * week). Only the first two meanings were supported by earlier    * versions of jdk.   *   * <dl>   * <dt><code>day &gt; 0, dayOfWeek = Calendar.WEEKDAY</code></dt>   * <dd>The start/end of daylight savings is on the <code>day</code>-th   * <code>WEEKDAY</code> in the given month. </dd>   * <dt><code>day &lt; 0, dayOfWeek = Calendar.WEEKDAY</code></dt>   * <dd>The start/end of daylight savings is on the <code>-day</code>-th   * <code>WEEKDAY</code> counted from the <i>end</i> of the month. </dd>   * <dt><code>day &gt; 0, dayOfWeek = 0</code></dt>   * <dd>The start/end of daylight is on the <code>day</code>-th day of   * the month. </dd>   * <dt><code>day &gt; 0, dayOfWeek = -Calendar.WEEKDAY</code></dt>   * <dd>The start/end of daylight is on the first WEEKDAY on or after   * the <code>day</code>-th day of the month.  You must make sure that   * this day lies in the same month. </dd>   * <dt><code>day &lt; 0, dayOfWeek = -Calendar.WEEKDAY</code></dt>   * <dd>The start/end of daylight is on the first WEEKDAY on or   * <i>before</i> the <code>-day</code>-th day of the month.  You   * must make sure that this day lies in the same month. </dd>   * </dl>   *   * If you give a non existing month, a day that is zero, or too big,    * or a dayOfWeek that is too big,  the result is undefined.   *   * The start rule must have a different month than the end rule.   * This restriction shouldn't hurt for all possible time zones.   *    * @param rawOffset The time offset from GMT in milliseconds.   * @param id  The identifier of this time zone.   * @param startMonth The start month of daylight savings; use the   * constants in Calendar.   * @param startday A day in month or a day of week number, as   * described above.   * @param startDayOfWeek The start rule day of week; see above.   * @param startTime A time in millis in standard time.   * @param endMonth The end month of daylight savings; use the   * constants in Calendar.   * @param endday A day in month or a day of week number, as    * described above.   * @param endDayOfWeek The end rule day of week; see above.   * @param endTime A time in millis in standard time.  */  public SimpleTimeZone(int rawOffset, String id,			int startMonth, int startDayOfWeekInMonth,			int startDayOfWeek, int startTime,			int endMonth, int endDayOfWeekInMonth,			int endDayOfWeek, int endTime)  {    this.rawOffset = rawOffset;    setID(id);    useDaylight = true;    setStartRule(startMonth, startDayOfWeekInMonth,		 startDayOfWeek, startTime);    setEndRule(endMonth, endDayOfWeekInMonth, endDayOfWeek, endTime);    if (startMonth == endMonth)      throw new IllegalArgumentException	("startMonth and endMonth must be different");    this.startYear = 0;  }  /**   * This constructs a new SimpleTimeZone that supports a daylight savings   * rule.  The parameter are the same as for the constructor above, except   * there is the additional dstSavaings parameter.   *   * @param dstSavings the amount of savings for daylight savings   * time in milliseconds.  This must be positive.   */  public SimpleTimeZone(int rawOffset, String id,			int startMonth, int startDayOfWeekInMonth,			int startDayOfWeek, int startTime,			int endMonth, int endDayOfWeekInMonth,			int endDayOfWeek, int endTime, int dstSavings)  {    this(rawOffset, id,	 startMonth, startDayOfWeekInMonth, startDayOfWeek, startTime,	 endMonth, endDayOfWeekInMonth, endDayOfWeek, endTime);    this.dstSavings = dstSavings;  }  /**   * Sets the first year, where daylight savings applies.  The daylight   * savings rule never apply for years in the BC era.  Note that this   * is gregorian calendar specific.   * @param year the start year.   */  public void setStartYear(int year)  {    startYear = year;    useDaylight = true;  }  /**   * Checks if the month, day, dayOfWeek arguments are in range and   * returns the mode of the rule.   * @param month the month parameter as in the constructor   * @param day the day parameter as in the constructor   * @param dayOfWeek the day of week parameter as in the constructor   * @return the mode of this rule see startMode.   * @exception IllegalArgumentException if parameters are out of range.   * @see #SimpleTimeZone(int, String, int, int, int, int, int, int, int, int)   * @see #startMode   */  private int checkRule(int month, int day, int dayOfWeek)  {    int daysInMonth = getDaysInMonth(month, 1);    if (dayOfWeek == 0)      {	if (day <= 0 || day > daysInMonth)	  throw new IllegalArgumentException("day out of range");	return DOM_MODE;      }    else if (dayOfWeek > 0)      {	if (Math.abs(day) > (daysInMonth + 6) / 7)	  throw new IllegalArgumentException("dayOfWeekInMonth out of range");	if (dayOfWeek > Calendar.SATURDAY)	  throw new IllegalArgumentException("dayOfWeek out of range");	return DOW_IN_MONTH_MODE;      }    else      {	if (day == 0 || Math.abs(day) > daysInMonth)	  throw new IllegalArgumentException("day out of range");	if (dayOfWeek < -Calendar.SATURDAY)	  throw new IllegalArgumentException("dayOfWeek out of range");	if (day < 0)	  return DOW_LE_DOM_MODE;	else	  return DOW_GE_DOM_MODE;      }  }  /**   * Sets the daylight savings start rule.  You must also set the   * end rule with <code>setEndRule</code> or the result of   * getOffset is undefined.  For the parameters see the ten-argument   * constructor above.   *   * @param month The month where daylight savings start, zero   * based.  You should use the constants in Calendar.   * @param day A day of month or day of week in month.   * @param dayOfWeek The day of week where daylight savings start.   * @param time The time in milliseconds standard time where daylight   * savings start.   * @see SimpleTimeZone */  public void setStartRule(int month, int day, int dayOfWeek, int time)  {    this.startMode = checkRule(month, day, dayOfWeek);    this.startMonth = month;    // FIXME: XXX: JDK 1.2 allows negative values and has 2 new variations    // of this method.    this.startDay = Math.abs(day);    this.startDayOfWeek = Math.abs(dayOfWeek);    this.startTime = time;    useDaylight = true;  }  /**   * Sets the daylight savings end rule.  You must also set the   * start rule with <code>setStartRule</code> or the result of   * getOffset is undefined. For the parameters see the ten-argument   * constructor above.   *   * @param rawOffset The time offset from GMT.   * @param id  The identifier of this time zone.   * @param Month The end month of daylight savings.   * @param day A day in month, or a day of week in month.   * @param DayOfWeek A day of week, when daylight savings ends.   * @param Time A time in millis in standard time.   * @see #setStartRule */  public void setEndRule(int month, int day, int dayOfWeek, int time)  {    this.endMode = checkRule(month, day, dayOfWeek);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -