1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.http;
24
25 import java.io.ObjectStreamException;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Map;
32
33 /***
34 * Enumeration of all possible time zones in Lotus Notes.
35 *
36 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
37 */
38 public final class DominoTimeZone {
39
40 /***
41 * value for field <tt>tz_dst</tt> for 'dailight saving time not
42 * observed'.
43 * TODO is this used somewhere?
44 */
45 public static final String DST_NOT_OBSERVED = "0";
46
47 /*** value for field <tt>tz_dst</tt> for 'dailight saving time observed'. */
48 public static final String DST_OBSERVED = "1";
49
50 /*** List of possible time zones in Lotus Notes. */
51 private static final List TIME_ZONES_LIST = new ArrayList();
52
53 /*** Map of possible time zones in Lotus Notes. */
54 private static final Map TIME_ZONES_MAP = new HashMap();
55
56 /*** name of the time zone. */
57 private final String fName;
58
59 /*** value of the time zone as for field <tt>tz_zone</tt>. */
60 private final String fValue;
61
62 /*** whether to observe dailight saving time or not. */
63 private final boolean fDst;
64
65 /***
66 * Constructor.
67 *
68 * @param name name of the time zone
69 * @param value value of the time zone
70 * @param dst observe daylight saving time
71 */
72 private DominoTimeZone(final String name, final String value, final boolean dst) {
73 fName = name;
74 fValue = value;
75 fDst = dst;
76 }
77
78 /***
79 * Returns the time zone value for a given name.
80 *
81 * @param name exact name of a time zone
82 * @return the time zone value
83 */
84 public static DominoTimeZone get(final String name) {
85 return (DominoTimeZone) TIME_ZONES_MAP.get(name);
86 }
87
88 /***
89 * Returns the time zone value for a given search string.
90 *
91 * <p>The search string is simply a partial string of a time zone name.</p>
92 *
93 * @param searchString search string of a time zone
94 * @return the time zone value or <code>null</code> if not found
95 */
96 public static DominoTimeZone searchTimeZone(final String searchString) {
97 if (searchString == null) {
98 return null;
99 }
100 Iterator iterator = TIME_ZONES_LIST.iterator();
101 while (iterator.hasNext()) {
102 DominoTimeZone timeZone = (DominoTimeZone) iterator.next();
103 if (timeZone.getName().indexOf(searchString) >= 0) {
104 return timeZone;
105 }
106 }
107 return null;
108 }
109
110 /***
111 * Returns whether daylight saving time should be observed.
112 *
113 * @return <code>true</code> if daylight saving time should be observed,
114 * else <code>false</code>
115 */
116 public boolean isDst() {
117 return fDst;
118 }
119
120 /***
121 * The name of the time zone.
122 *
123 * @return time zone name
124 */
125 public String getName() {
126 return fName;
127 }
128
129 /***
130 * The value of the time zone.
131 *
132 * @return the time zone value
133 */
134 public String getValue() {
135 return fValue;
136 }
137
138 /***
139 * The value of the time zone.
140 *
141 * @return time zone value
142 */
143 public String getTimeZones() {
144 return fValue;
145 }
146
147 /***
148 * Collection of all time zone values.
149 *
150 * @return collection of time zone values
151 */
152 public Collection getTimeZoneValues() {
153 return TIME_ZONES_MAP.values();
154 }
155
156 static {
157 addTimeZone("(GMT-12:00) International Date Line West", "Dateline:12:0", false);
158 addTimeZone("(GMT-11:00) Midway Island, Samoa", "Samoa:11:0", false);
159 addTimeZone("(GMT-10:00) Hawaii", "Hawaiian:10:0", false);
160 addTimeZone("(GMT-09:00) Alaska", "Alaskan:9:4|1|1|10|-1|1", true);
161 addTimeZone("(GMT-08:00) Pacific Time (US & Canada); Tijuana", "Pacific:8:4|1|1|10|-1|1", true);
162 addTimeZone("(GMT-07:00) Mountain Time (US & Canada)", "Mountain:7:4|1|1|10|-1|1", true);
163 addTimeZone("(GMT-07:00) Chihuahua, La Paz, Mazatlan", "Mexico%202:7:5|1|1|9|-1|1", true);
164 addTimeZone("(GMT-07:00) Arizona", "US%20Mountain:7:0", false);
165 addTimeZone("(GMT-06:00) Central Time (US & Canada)", "Central:6:4|1|1|10|-1|1", true);
166 addTimeZone("(GMT-06:00) Guadalajara, Mexico City, Monterrey", "Mexico:6:4|1|1|9|-1|1", true);
167 addTimeZone("(GMT-06:00) Central America, Saskatchewan", "Central%20America/Canada%20Central:6:0", false);
168 addTimeZone("(GMT-05:00) Eastern Time (US & Canada)", "Eastern:5:4|1|1|10|-1|1", true);
169 addTimeZone("(GMT-05:00) Indiana(East), Bogota, Lima, Quito", "US%20Eastern/SA%20Pacific:5:0", false);
170 addTimeZone("(GMT-04:00) Atlantic Time (Canada)", "Atlantic:4:4|1|1|10|-1|1", true);
171 addTimeZone("(GMT-04:00) Santiago", "Pacific%20SA:4:10|2|7|3|2|7", true);
172 addTimeZone("(GMT-04:00) Caracas, La Paz", "SA%20Western:4:0", false);
173 addTimeZone("(GMT-03:30) Newfoundland", "Newfoundland:3003:4|1|1|10|-1|1", true);
174 addTimeZone("(GMT-03:00) Brasilia", "E.%20South%20America:3:10|3|1|2|2|1", true);
175 addTimeZone("(GMT-03:00) Greenland", "Greenland:3:4|1|1|10|-1|1", true);
176 addTimeZone("(GMT-03:00) Buenos Aires, Georgetown", "SA%20Eastern:3:0", false);
177 addTimeZone("(GMT-02:00) Mid-Atlantic", "Mid-Atlnatic:2:3|-1|1|9|-1|1", true);
178 addTimeZone("(GMT-01:00) Azores", "Azores:1:3|-1|1|10|-1|1", true);
179 addTimeZone("(GMT-01:00) Cape Verde Is.", "Cape%20Verde:1:0", false);
180 addTimeZone("(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London", "GMT:0:3|-1|1|10|-1|1", true);
181 addTimeZone("(GMT) Casablanca, Monrovia", "Greenwich:0:0", false);
182 addTimeZone("(GMT+01:00) Central European", "Western/Central%20Europe:-1:3|-1|1|10|-1|1", true);
183 addTimeZone("(GMT+01:00) West Central Africa", "W.%20Central%20Africa:-1:0", false);
184 addTimeZone("(GMT+02:00) Eastern European", "Eastern%20Europe:-2:3|-1|1|10|-1|1", true);
185 addTimeZone("(GMT+02:00) Cairo", "Egypt:-2:5|1|6|9|-1|4", true);
186 addTimeZone("(GMT+02:00) Jerusalem, Harare, Pretoria", "Israel/South%20Africa:-2:0", false);
187 addTimeZone("(GMT+03:00) Moscow, St. Petersburg, Volgograd", "Russian:-3:3|-1|1|10|-1|1", true);
188 addTimeZone("(GMT+03:00) Baghdad", "Arabic:-3:4|1|1|10|1|1", true);
189 addTimeZone("(GMT+03:00) Kuwait, Riyadh, Nairobi", "Arab/E.%20Africa:-3:0", false);
190 addTimeZone("(GMT+03:30) Tehran", "Iran:-3003:3|1|1|9|4|3", true);
191 addTimeZone("(GMT+04:00) Baku, Tbilisi, Yerevan", "Caucasus:-4:3|-1|1|10|-1|1", true);
192 addTimeZone("(GMT+04:00) Abu Dhabi, Muscat", "Arabian:-4:0", false);
193 addTimeZone("(GMT+04:30) Kabul", "Afghanistan:-3004:0", false);
194 addTimeZone("(GMT+05:00) Ekaterinburg", "Ekaterinburg:-5:3|-1|1|10|-1|1", true);
195 addTimeZone("(GMT+05:00) Islamabad, Karachi, Tashkent", "West%20Asia:-5:0", false);
196 addTimeZone("(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi", "India:-3005:0", false);
197 addTimeZone("(GMT+05:45) Kathmandu", "Nepal:-4505:0", false);
198 addTimeZone("(GMT+06:00) Almaty, Novosibirsk", "N.%20Central%20Asia:-6:3|-1|1|10|-1|1", true);
199 addTimeZone("(GMT+06:00) Astana, Dhaka, Sri Jayawardenepura", "Central%20Asia/Sri%20Lanka:-6:0", false);
200 addTimeZone("(GMT+06:30) Rangoon", "Myanmar:-3006:0", false);
201 addTimeZone("(GMT+07:00) Bangkok, Hanoi, Jakarta", "SE%20Asia:-7:0", false);
202 addTimeZone("(GMT+07:00) Krasnoyarsk", "North%20Asia:-7:3|-1|1|10|-1|1", true);
203 addTimeZone("(GMT+08:00) Beijing, Taipei, Singapore, Perth", "China/Singapore/Taiwan/W.%20Australia:-8:0", false);
204 addTimeZone("(GMT+08:00) Irkutsk, Ulaan Bataar", "North%20Asia%20East:-8:3|-1|1|10|-1|1", true);
205 addTimeZone("(GMT+09:00) Seoul, Tokyo", "Japan/Korea:-9:0", false);
206 addTimeZone("(GMT+09:00) Yakutsk", "Yakutsk:-9:3|-1|1|10|-1|1", true);
207 addTimeZone("(GMT+09:30) Adelaide", "Cen.%20Australia:-3009:10|-1|1|3|-1|1", true);
208 addTimeZone("(GMT+09:30) Darwin", "AUS%20Central:-3009:0", false);
209 addTimeZone("(GMT+10:00) Canberra, Melbourne, Sydney", "AUS%20Eastern:-10:10|-1|1|3|-1|1", true);
210 addTimeZone("(GMT+10:00) Vladivostok", "Vladivostok:-10:3|-1|1|10|-1|1", true);
211 addTimeZone("(GMT+10:00) Hobart", "Tasmania:-10:10|1|1|3|-1|1", true);
212 addTimeZone("(GMT+10:00) Brisbane, Guam, Port Moresby", "E.%20Australia/West%20Pacific:-10:0", false);
213 addTimeZone("(GMT+11:00) Magadan, Solomon Is., New Caledonia", "Central%20Pacific:-11:0", false);
214 addTimeZone("(GMT+12:00) Auckland, Wellington", "New%20Zealand:-12:10|1|1|3|3|1", true);
215 addTimeZone("(GMT+12:00) Fiji, Kamchatka, Marchall Is.", "Fiji:-12:0", false);
216 addTimeZone("(GMT+13:00) Nuku\'alofa", "Tonga:-13:0", false);
217 }
218
219 /***
220 * Adds a time zone to the list of time zones possible in Lotus Notes.
221 *
222 * @param name name of the time zone
223 * @param value value of the time zone
224 * @param dst observe daylight saving time
225 */
226 private static void addTimeZone(final String name, final String value, final boolean dst) {
227 DominoTimeZone dominoTimeZone = new DominoTimeZone(name, value, dst);
228 TIME_ZONES_LIST.add(dominoTimeZone);
229 TIME_ZONES_MAP.put(name, dominoTimeZone);
230 }
231
232 /***
233 * {@inheritDoc}
234 * @see java.lang.Object#equals(java.lang.Object)
235 */
236 public boolean equals(final Object obj) {
237 if (obj == null) {
238 return false;
239 }
240 if (!(obj instanceof DominoTimeZone)) {
241 return false;
242 }
243 final DominoTimeZone dtz = (DominoTimeZone) obj;
244 return fName.equals(dtz.fName) && fValue.equals(dtz.fValue) && fDst == dtz.fDst;
245 }
246
247 /***
248 * {@inheritDoc}
249 * @see java.lang.Object#hashCode()
250 */
251 public int hashCode() {
252 return (fName + fValue + fDst).hashCode();
253 }
254
255 /***
256 * {@inheritDoc}
257 * @see java.lang.Object#toString()
258 */
259 public String toString() {
260 return "[name=" + fName + ", value=" + fValue + ", dst=" + fDst + "]";
261 }
262
263 /***
264 * Serialization helper used to resolve the enumeration instances.
265 */
266 private Object readResolve() throws ObjectStreamException {
267 return TIME_ZONES_MAP.get(this.fName);
268 }
269 }