📄 timezoneimpl.java
字号:
case DOW_LE_DOM_MODE: ruleDayOfMonth = ruleDay - (49 - ruleDayOfWeek + ruleDay + dayOfWeek - dayOfMonth) % 7; // Note at this point ruleDayOfMonth may be <1, although it will // be >=1 for well-formed rules. break; } if (dayOfMonth < ruleDayOfMonth) return -1; else if (dayOfMonth > ruleDayOfMonth) return 1; if (millis < ruleMillis) return -1; else if (millis > ruleMillis) return 1; else return 0; } /** * Gets the GMT offset for this time zone. */ public int getRawOffset() { // The given date will be taken into account while // we have the historical time zone data in place. return rawOffset; } /** * Queries if this time zone uses Daylight Savings Time. */ public boolean useDaylightTime() { return useDaylight; } /** * Gets the ID of this time zone. * @return the ID of this time zone. */ public String getID() { return ID; } /** * Gets the <code>TimeZone</code> for the given ID. * @param ID the ID for a <code>TimeZone</code>, either an abbreviation such as * "GMT", or a full name such as "America/Los_Angeles". * <p> The only time zone ID that is required to be supported is "GMT", * though typically, the timezones for the regions where the device is * sold should be supported. * @return the specified <code>TimeZone</code>, or null if the given ID * cannot be understood. */ public synchronized TimeZone getInstance(String ID) { if (ID == null) { if (HOME_ID == null) { HOME_ID = System.getProperty("com.sun.cldc.util.j2me.TimeZoneImpl.timezone"); if (HOME_ID == null) HOME_ID = "UTC"; } ID = HOME_ID; } for (int i = 0; i < zones.length; i++) if (zones[i].getID().equals(ID)) return zones[i]; return null; } /** Gets all the available IDs supported. * @return an array of IDs. */ public synchronized String[] getIDs() { if (ids == null) { ids = new String[zones.length]; for (int i = 0; i < zones.length; i++) ids[i] = zones[i].getID(); } return ids; } // =======================privates=============================== /** * The string identifier of this <code>TimeZone</code>. This is a * programmatic identifier used internally to look up <code>TimeZone</code> * objects from the system table and also to map them to their localized * display names. <code>ID</code> values are unique in the system * table but may not be for dynamically created zones. * @serial */ private String ID; static String[] ids = null; /** * The month in which daylight savings time starts. This value must be * between <code>Calendar.JANUARY</code> and * <code>Calendar.DECEMBER</code> inclusive. This value must not equal * <code>endMonth</code>. * <p>If <code>useDaylight</code> is false, this value is ignored. * @serial */ private int startMonth; /** * This field has two possible interpretations: * <dl> * <dt><code>startMode == DOW_IN_MONTH</code></dt> * <dd> * <code>startDay</code> indicates the day of the month of * <code>startMonth</code> on which daylight * savings time starts, from 1 to 28, 30, or 31, depending on the * <code>startMonth</code>. * </dd> * <dt><code>startMode != DOW_IN_MONTH</code></dt> * <dd> * <code>startDay</code> indicates which <code>startDayOfWeek</code> in th * month <code>startMonth</code> daylight * savings time starts on. For example, a value of +1 and a * <code>startDayOfWeek</code> of <code>Calendar.SUNDAY</code> indicates the * first Sunday of <code>startMonth</code>. Likewise, +2 would indicate the * second Sunday, and -1 the last Sunday. A value of 0 is illegal. * </dd> * </ul> * <p>If <code>useDaylight</code> is false, this value is ignored. * @serial */ private int startDay; /** * The day of the week on which daylight savings time starts. This value * must be between <code>Calendar.SUNDAY</code> and * <code>Calendar.SATURDAY</code> inclusive. * <p>If <code>useDaylight</code> is false or * <code>startMode == DAY_OF_MONTH</code>, this value is ignored. * @serial */ private int startDayOfWeek; /** * The time in milliseconds after midnight at which daylight savings * time starts. This value is expressed as <em>wall time</em>, which means * it is compared to <em>standard</em> time for the daylight savings start. * <p>If <code>useDaylight</code> is false, this value is ignored. * @serial */ private int startTime; /** * The month in which daylight savings time ends. This value must be * between <code>Calendar.JANUARY</code> and * <code>Calendar.UNDECIMBER</code>. This value must not equal * <code>startMonth</code>. * <p>If <code>useDaylight</code> is false, this value is ignored. * @serial */ private int endMonth; /** * This field has two possible interpretations: * <dl> * <dt><code>endMode == DOW_IN_MONTH</code></dt> * <dd> * <code>endDay</code> indicates the day of the month of * <code>endMonth</code> on which daylight * savings time ends, from 1 to 28, 30, or 31, depending on the * <code>endMonth</code>. * </dd> * <dt><code>endMode != DOW_IN_MONTH</code></dt> * <dd> * <code>endDay</code> indicates which <code>endDayOfWeek</code> in th * month <code>endMonth</code> daylight * savings time ends on. For example, a value of +1 and a * <code>endDayOfWeek</code> of <code>Calendar.SUNDAY</code> indicates the * first Sunday of <code>endMonth</code>. Likewise, +2 would indicate the * second Sunday, and -1 the last Sunday. A value of 0 is illegal. * </dd> * </ul> * <p>If <code>useDaylight</code> is false, this value is ignored. * @serial */ private int endDay; /** * The day of the week on which daylight savings time ends. This value * must be between <code>Calendar.SUNDAY</code> and * <code>Calendar.SATURDAY</code> inclusive. * <p>If <code>useDaylight</code> is false or * <code>endMode == DAY_OF_MONTH</code>, this value is ignored. * @serial */ private int endDayOfWeek; /** * The time in milliseconds after midnight at which daylight savings * time ends. This value is expressed as <em>wall time</em>, which means * it is compared to <em>daylight</em> time for the daylight savings end. * <p>If <code>useDaylight</code> is false, this value is ignored. * @serial */ private int endTime; /** * The year in which daylight savings time is first observed. This is an AD * value. If this value is less than 1 then daylight savings is observed * for all AD years. * <p>If <code>useDaylight</code> is false, this value is ignored. * @serial */ private int startYear; /** * The offset in milliseconds between this zone and GMT. Negative offsets * are to the west of Greenwich. To obtain local <em>standard</em> time, * add the offset to GMT time. To obtain local wall time it may also be * necessary to add <code>dstSavings</code>. * @serial */ private int rawOffset; /** * A boolean value which is true if and only if this zone uses daylight * savings time. If this value is false, several other fields are ignored. * @serial */ private boolean useDaylight=false; // indicate if this time zone uses DST private static final int millisPerHour = 60*60*1000; private static final int millisPerDay = 24*millisPerHour; /** * This field was serialized in JDK 1.1, so we have to keep it that way * to maintain serialization compatibility. However, there's no need to * recreate the array each time we create a new time zone. * @serial An array of bytes containing the values {31, 28, 31, 30, 31, 30, * 31, 31, 30, 31, 30, 31}. This is ignored as of JDK 1.2, however, it must * be streamed out for compatibility with JDK 1.1. */ private final byte monthLength[] = staticMonthLength; private final static byte staticMonthLength[] = {31,29,31,30,31,30,31,31,30,31,30,31}; //**NS** /** * Variables specifying the mode of the start rule. Takes the following * values: * <dl> * <dt><code>DOM_MODE</code></dt> * <dd> * Exact day of week; e.g., March 1. * </dd> * <dt><code>DOW_IN_MONTH_MODE</code></dt> * <dd> * Day of week in month; e.g., last Sunday in March. * </dd> * <dt><code>DOW_GE_DOM_MODE</code></dt> * <dd> * Day of week after day of month; e.g., Sunday on or after March 15. * </dd> * <dt><code>DOW_LE_DOM_MODE</code></dt> * <dd> * Day of week before day of month; e.g., Sunday on or before March 15. * </dd> * </dl> * The setting of this field affects the interpretation of the * <code>startDay</code> field. * <p>If <code>useDaylight</code> is false, this value is ignored. * @serial * @since JDK1.1.4 */ private int startMode; /** * Variables specifying the mode of the end rule. Takes the following
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -