2 *******************************************************************************
3 * Copyright (C) 2007-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
7 package com.ibm.icu.util;
9 import java.io.Serializable;
10 import java.util.Date;
13 * <code>TimeZoneRule</code> is an abstract class representing a rule for time zone.
14 * <code>TimeZoneRule</code> has a set of time zone attributes, such as zone name,
15 * raw offset (UTC offset for standard time) and daylight saving time offset.
17 * @see com.ibm.icu.util.TimeZoneTransition
18 * @see com.ibm.icu.util.RuleBasedTimeZone
22 public abstract class TimeZoneRule implements Serializable {
24 private static final long serialVersionUID = 6374143828553768100L;
26 private final String name;
27 private final int rawOffset;
28 private final int dstSavings;
31 * Constructs a <code>TimeZoneRule</code> with the name, the GMT offset of its
32 * standard time and the amount of daylight saving offset adjustment.
34 * @param name The time zone name.
35 * @param rawOffset The UTC offset of its standard time in milliseconds.
36 * @param dstSavings The amount of daylight saving offset adjustment in milliseconds.
37 * If this is a rule for standard time, the value of this argument is 0.
41 public TimeZoneRule(String name, int rawOffset, int dstSavings) {
43 this.rawOffset = rawOffset;
44 this.dstSavings = dstSavings;
48 * Gets the name of this time zone.
50 * @return The name of this time zone.
54 public String getName() {
59 * Gets the standard time offset.
61 * @return The standard time offset from UTC in milliseconds.
65 public int getRawOffset() {
70 * Gets the amount of daylight saving delta time from the standard time.
72 * @return The amount of daylight saving offset used by this rule
77 public int getDSTSavings() {
82 * Returns if this rule represents the same rule and offsets as another.
83 * When two <code>TimeZoneRule</code> objects differ only its names, this method returns
86 * @param other The <code>TimeZoneRule</code> object to be compared with.
87 * @return true if the other <code>TimeZoneRule</code> is the same as this one.
91 public boolean isEquivalentTo(TimeZoneRule other) {
92 if (rawOffset == other.rawOffset && dstSavings == other.dstSavings) {
99 * Gets the very first time when this rule takes effect.
101 * @param prevRawOffset The standard time offset from UTC before this rule
102 * takes effect in milliseconds.
103 * @param prevDSTSavings The amount of daylight saving offset from the
106 * @return The very first time when this rule takes effect.
110 public abstract Date getFirstStart(int prevRawOffset, int prevDSTSavings);
113 * Gets the final time when this rule takes effect.
115 * @param prevRawOffset The standard time offset from UTC before this rule
116 * takes effect in milliseconds.
117 * @param prevDSTSavings The amount of daylight saving offset from the
120 * @return The very last time when this rule takes effect,
121 * or null if this rule is applied for future dates infinitely.
125 public abstract Date getFinalStart(int prevRawOffset, int prevDSTSavings);
128 * Gets the first time when this rule takes effect after the specified time.
130 * @param base The first time after this time is returned.
131 * @param prevRawOffset The standard time offset from UTC before this rule
132 * takes effect in milliseconds.
133 * @param prevDSTSavings The amount of daylight saving offset from the
135 * @param inclusive Whether the base time is inclusive or not.
137 * @return The first time when this rule takes effect after the specified time,
138 * or null when this rule never takes effect after the specified time.
142 public abstract Date getNextStart(long base, int prevRawOffset, int prevDSTSavings, boolean inclusive);
145 * Gets the most recent time when this rule takes effect before the specified time.
147 * @param base The most recent time when this rule takes effect before
148 * this time is returned.
149 * @param prevRawOffset The standard time offset from UTC before this rule
150 * takes effect in milliseconds.
151 * @param prevDSTSavings The amount of daylight saving offset from the
153 * @param inclusive Whether the base time is inclusive or not.
155 * @return The most recent time when this rule takes effect before the specified time,
156 * or null when this rule never takes effect before the specified time.
160 public abstract Date getPreviousStart(long base, int prevRawOffset, int prevDSTSavings, boolean inclusive);
163 * Returns if this <code>TimeZoneRule</code> has one or more start times.
165 * @return true if this <TimeZoneRule</code> has one or more start times.
169 public abstract boolean isTransitionRule();
172 * Returns a <code>String</code> representation of this <code>TimeZoneRule</code> object.
173 * This method is used for debugging purpose only. The string representation can be changed
174 * in future version of ICU without any notice.
177 public String toString() {
178 StringBuilder buf = new StringBuilder();
179 buf.append("name=" + name);
180 buf.append(", stdOffset=" + rawOffset);
181 buf.append(", dstSaving=" + dstSavings);
182 return buf.toString();