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