1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 /* 5 ******************************************************************************* 6 * Copyright (C) 2007-2016, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10 package android.icu.util; 11 12 import java.io.Serializable; 13 import java.util.Date; 14 15 /** 16 * <code>TimeZoneRule</code> is an abstract class representing a rule for time zone. 17 * <code>TimeZoneRule</code> has a set of time zone attributes, such as zone name, 18 * raw offset (UTC offset for standard time) and daylight saving time offset. 19 * 20 * @see android.icu.util.TimeZoneTransition 21 * @see android.icu.util.RuleBasedTimeZone 22 * 23 * @hide Only a subset of ICU is exposed in Android 24 */ 25 public abstract class TimeZoneRule implements Serializable { 26 27 private static final long serialVersionUID = 6374143828553768100L; 28 29 private final String name; 30 private final int rawOffset; 31 private final int dstSavings; 32 33 /** 34 * Constructs a <code>TimeZoneRule</code> with the name, the GMT offset of its 35 * standard time and the amount of daylight saving offset adjustment. 36 * 37 * @param name The time zone name. 38 * @param rawOffset The UTC offset of its standard time in milliseconds. 39 * @param dstSavings The amount of daylight saving offset adjustment in milliseconds. 40 * If this is a rule for standard time, the value of this argument is 0. 41 */ TimeZoneRule(String name, int rawOffset, int dstSavings)42 public TimeZoneRule(String name, int rawOffset, int dstSavings) { 43 this.name = name; 44 this.rawOffset = rawOffset; 45 this.dstSavings = dstSavings; 46 } 47 48 /** 49 * Gets the name of this time zone. 50 * 51 * @return The name of this time zone. 52 */ getName()53 public String getName() { 54 return name; 55 } 56 57 /** 58 * Gets the standard time offset. 59 * 60 * @return The standard time offset from UTC in milliseconds. 61 */ getRawOffset()62 public int getRawOffset() { 63 return rawOffset; 64 } 65 66 /** 67 * Gets the amount of daylight saving delta time from the standard time. 68 * 69 * @return The amount of daylight saving offset used by this rule 70 * in milliseconds. 71 */ getDSTSavings()72 public int getDSTSavings() { 73 return dstSavings; 74 } 75 76 /** 77 * Returns if this rule represents the same rule and offsets as another. 78 * When two <code>TimeZoneRule</code> objects differ only its names, this method returns 79 * true. 80 * 81 * @param other The <code>TimeZoneRule</code> object to be compared with. 82 * @return true if the other <code>TimeZoneRule</code> is the same as this one. 83 */ isEquivalentTo(TimeZoneRule other)84 public boolean isEquivalentTo(TimeZoneRule other) { 85 if (rawOffset == other.rawOffset && dstSavings == other.dstSavings) { 86 return true; 87 } 88 return false; 89 } 90 91 /** 92 * Gets the very first time when this rule takes effect. 93 * 94 * @param prevRawOffset The standard time offset from UTC before this rule 95 * takes effect in milliseconds. 96 * @param prevDSTSavings The amount of daylight saving offset from the 97 * standard time. 98 * 99 * @return The very first time when this rule takes effect. 100 */ getFirstStart(int prevRawOffset, int prevDSTSavings)101 public abstract Date getFirstStart(int prevRawOffset, int prevDSTSavings); 102 103 /** 104 * Gets the final time when this rule takes effect. 105 * 106 * @param prevRawOffset The standard time offset from UTC before this rule 107 * takes effect in milliseconds. 108 * @param prevDSTSavings The amount of daylight saving offset from the 109 * standard time. 110 * 111 * @return The very last time when this rule takes effect, 112 * or null if this rule is applied for future dates infinitely. 113 */ getFinalStart(int prevRawOffset, int prevDSTSavings)114 public abstract Date getFinalStart(int prevRawOffset, int prevDSTSavings); 115 116 /** 117 * Gets the first time when this rule takes effect after the specified time. 118 * 119 * @param base The first time after this time is returned. 120 * @param prevRawOffset The standard time offset from UTC before this rule 121 * takes effect in milliseconds. 122 * @param prevDSTSavings The amount of daylight saving offset from the 123 * standard time. 124 * @param inclusive Whether the base time is inclusive or not. 125 * 126 * @return The first time when this rule takes effect after the specified time, 127 * or null when this rule never takes effect after the specified time. 128 */ getNextStart(long base, int prevRawOffset, int prevDSTSavings, boolean inclusive)129 public abstract Date getNextStart(long base, int prevRawOffset, int prevDSTSavings, boolean inclusive); 130 131 /** 132 * Gets the most recent time when this rule takes effect before the specified time. 133 * 134 * @param base The most recent time when this rule takes effect before 135 * this time is returned. 136 * @param prevRawOffset The standard time offset from UTC before this rule 137 * takes effect in milliseconds. 138 * @param prevDSTSavings The amount of daylight saving offset from the 139 * standard time. 140 * @param inclusive Whether the base time is inclusive or not. 141 * 142 * @return The most recent time when this rule takes effect before the specified time, 143 * or null when this rule never takes effect before the specified time. 144 */ getPreviousStart(long base, int prevRawOffset, int prevDSTSavings, boolean inclusive)145 public abstract Date getPreviousStart(long base, int prevRawOffset, int prevDSTSavings, boolean inclusive); 146 147 /** 148 * Returns if this <code>TimeZoneRule</code> has one or more start times. 149 * 150 * @return true if this <code>TimeZoneRule</code> has one or more start times. 151 */ isTransitionRule()152 public abstract boolean isTransitionRule(); 153 154 /** 155 * Returns a <code>String</code> representation of this <code>TimeZoneRule</code> object. 156 * This method is used for debugging purpose only. The string representation can be changed 157 * in future version of ICU without any notice. 158 */ 159 @Override toString()160 public String toString() { 161 StringBuilder buf = new StringBuilder(); 162 buf.append("name=" + name); 163 buf.append(", stdOffset=" + rawOffset); 164 buf.append(", dstSaving=" + dstSavings); 165 return buf.toString(); 166 } 167 } 168