📄 simpletimezone.java
字号:
/* java.util.SimpleTimeZone Copyright (C) 1998, 1999, 2000, 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 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;/** * 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 GregorianCalendar * @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 hour. * @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; /** * This variable specifies the mode that startTime is specified in. By * default it is WALL_TIME, but can also be STANDARD_TIME or UTC_TIME. For * startTime, STANDARD_TIME and WALL_TIME are equivalent. * @serial */ private int startTimeMode = WALL_TIME; /** * 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 specifies the mode that endTime is specified in. By * default it is WALL_TIME, but can also be STANDARD_TIME or UTC_TIME. * @serial */ private int endTimeMode = WALL_TIME; /** * 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> * </dl> * * 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 = 2; private static final long serialVersionUID = -403250971215465050L; /** * Constant to indicate that start and end times are specified in standard * time, without adjusting for daylight savings. */ public static final int STANDARD_TIME = 1; /** * Constant to indicate that start and end times are specified in wall * time, adjusting for daylight savings. This is the default. */ public static final int WALL_TIME = 0; /** * Constant to indicate that start and end times are specified in UTC. */ public static final int UTC_TIME = 2; /** * 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 > 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 < 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 > 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 > 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 < 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 startDayOfWeekInMonth 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 endDayOfWeekInMonth 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. * @throws IllegalArgumentException if parameters are invalid or out of * range. */ 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. * @since 1.2 */ 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -