2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / util / TimeZone.java
blob2636956527df0b70202c856f27a1ae7ea8db8f91
1 /* java.util.TimeZone
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA.
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
25 combination.
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package java.util;
41 import java.text.DateFormatSymbols;
42 import gnu.classpath.Configuration;
44 /**
45 * This class represents a time zone offset and handles daylight savings.
47 * You can get the default time zone with <code>getDefault</code>.
48 * This represents the time zone where program is running.
50 * Another way to create a time zone is <code>getTimeZone</code>, where
51 * you can give an identifier as parameter. For instance, the identifier
52 * of the Central European Time zone is "CET".
54 * With the <code>getAvailableIDs</code> method, you can get all the
55 * supported time zone identifiers.
57 * @see Calendar
58 * @see SimpleTimeZone
59 * @author Jochen Hoenicke
61 public abstract class TimeZone implements java.io.Serializable, Cloneable
64 /**
65 * Constant used to indicate that a short timezone abbreviation should
66 * be returned, such as "EST"
68 public static final int SHORT = 0;
70 /**
71 * Constant used to indicate that a long timezone name should be
72 * returned, such as "Eastern Standard Time".
74 public static final int LONG = 1;
76 /**
77 * The time zone identifier, e.g. PST.
79 private String ID;
81 /**
82 * The default time zone, as returned by getDefault.
84 private static TimeZone defaultZone0;
85 /* initialize this static field lazily to overhead if
86 * it is not needed:
88 private static synchronized TimeZone defaultZone() {
89 /* Look up default timezone */
90 if (defaultZone0 == null)
92 if (Configuration.INIT_LOAD_LIBRARY)
94 System.loadLibrary("javautil");
96 String tzid = System.getProperty("user.timezone");
98 if (tzid == null)
99 tzid = getDefaultTimeZoneId();
101 if (tzid == null)
102 tzid = "GMT";
104 defaultZone0 = getTimeZone(tzid);
106 return defaultZone0;
110 private static final long serialVersionUID = 3581463369166924961L;
113 * Hashtable for timezones by ID.
115 private static Hashtable timezones0;
116 /* initialize this static field lazily to overhead if
117 * it is not needed:
119 private static synchronized Hashtable timezones() {
120 if (timezones0==null)
122 Hashtable timezones = new Hashtable();
123 timezones0 = timezones;
125 TimeZone tz;
126 // Automatically generated by scripts/timezones.pl
127 // XXX - Should we read this data from a file?
128 tz = new SimpleTimeZone(-11000 * 3600, "MIT");
129 timezones0.put("MIT", tz);
130 timezones0.put("Pacific/Apia", tz);
131 timezones0.put("Pacific/Midway", tz);
132 timezones0.put("Pacific/Niue", tz);
133 timezones0.put("Pacific/Pago_Pago", tz);
134 tz = new SimpleTimeZone
135 (-10000 * 3600, "America/Adak",
136 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
137 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
138 timezones0.put("America/Adak", tz);
139 tz = new SimpleTimeZone(-10000 * 3600, "HST");
140 timezones0.put("HST", tz);
141 timezones0.put("Pacific/Fakaofo", tz);
142 timezones0.put("Pacific/Honolulu", tz);
143 timezones0.put("Pacific/Johnston", tz);
144 timezones0.put("Pacific/Rarotonga", tz);
145 timezones0.put("Pacific/Tahiti", tz);
146 tz = new SimpleTimeZone(-9500 * 3600, "Pacific/Marquesas");
147 timezones0.put("Pacific/Marquesas", tz);
148 tz = new SimpleTimeZone
149 (-9000 * 3600, "AST",
150 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
151 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
152 timezones0.put("AST", tz);
153 timezones0.put("America/Anchorage", tz);
154 timezones0.put("America/Juneau", tz);
155 timezones0.put("America/Nome", tz);
156 timezones0.put("America/Yakutat", tz);
157 tz = new SimpleTimeZone(-9000 * 3600, "Pacific/Gambier");
158 timezones0.put("Pacific/Gambier", tz);
159 tz = new SimpleTimeZone
160 (-8000 * 3600, "PST",
161 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
162 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
163 timezones0.put("PST", tz);
164 timezones0.put("PST8PDT", tz);
165 timezones0.put("America/Dawson", tz);
166 timezones0.put("America/Los_Angeles", tz);
167 timezones0.put("America/Tijuana", tz);
168 timezones0.put("America/Vancouver", tz);
169 timezones0.put("America/Whitehorse", tz);
170 timezones0.put("US/Pacific-New", tz);
171 tz = new SimpleTimeZone(-8000 * 3600, "Pacific/Pitcairn");
172 timezones0.put("Pacific/Pitcairn", tz);
173 tz = new SimpleTimeZone
174 (-7000 * 3600, "MST",
175 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
176 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
177 timezones0.put("MST", tz);
178 timezones0.put("MST7MDT", tz);
179 timezones0.put("America/Boise", tz);
180 timezones0.put("America/Chihuahua", tz);
181 timezones0.put("America/Denver", tz);
182 timezones0.put("America/Edmonton", tz);
183 timezones0.put("America/Inuvik", tz);
184 timezones0.put("America/Mazatlan", tz);
185 timezones0.put("America/Shiprock", tz);
186 timezones0.put("America/Yellowknife", tz);
187 tz = new SimpleTimeZone(-7000 * 3600, "MST7");
188 timezones0.put("MST7", tz);
189 timezones0.put("PNT", tz);
190 timezones0.put("America/Dawson_Creek", tz);
191 timezones0.put("America/Hermosillo", tz);
192 timezones0.put("America/Phoenix", tz);
193 tz = new SimpleTimeZone
194 (-6000 * 3600, "CST",
195 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
196 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
197 timezones0.put("CST", tz);
198 timezones0.put("CST6CDT", tz);
199 timezones0.put("America/Cambridge_Bay", tz);
200 timezones0.put("America/Cancun", tz);
201 timezones0.put("America/Chicago", tz);
202 timezones0.put("America/Menominee", tz);
203 timezones0.put("America/Merida", tz);
204 timezones0.put("America/Mexico_City", tz);
205 timezones0.put("America/Monterrey", tz);
206 timezones0.put("America/Rainy_River", tz);
207 timezones0.put("America/Winnipeg", tz);
208 tz = new SimpleTimeZone(-6000 * 3600, "America/Belize");
209 timezones0.put("America/Belize", tz);
210 timezones0.put("America/Costa_Rica", tz);
211 timezones0.put("America/El_Salvador", tz);
212 timezones0.put("America/Guatemala", tz);
213 timezones0.put("America/Managua", tz);
214 timezones0.put("America/Regina", tz);
215 timezones0.put("America/Swift_Current", tz);
216 timezones0.put("America/Tegucigalpa", tz);
217 timezones0.put("Pacific/Galapagos", tz);
218 tz = new SimpleTimeZone
219 (-6000 * 3600, "Pacific/Easter",
220 Calendar.OCTOBER, 9, -Calendar.SUNDAY, 0 * 3600,
221 Calendar.MARCH, 9, -Calendar.SUNDAY, 0 * 3600);
222 timezones0.put("Pacific/Easter", tz);
223 tz = new SimpleTimeZone
224 (-5000 * 3600, "America/Grand_Turk",
225 Calendar.APRIL, 1, Calendar.SUNDAY, 0 * 3600,
226 Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
227 timezones0.put("America/Grand_Turk", tz);
228 timezones0.put("America/Havana", tz);
229 tz = new SimpleTimeZone(-5000 * 3600, "EST5");
230 timezones0.put("EST5", tz);
231 timezones0.put("IET", tz);
232 timezones0.put("America/Bogota", tz);
233 timezones0.put("America/Cayman", tz);
234 timezones0.put("America/Eirunepe", tz);
235 timezones0.put("America/Guayaquil", tz);
236 timezones0.put("America/Indiana/Indianapolis", tz);
237 timezones0.put("America/Indiana/Knox", tz);
238 timezones0.put("America/Indiana/Marengo", tz);
239 timezones0.put("America/Indiana/Vevay", tz);
240 timezones0.put("America/Indianapolis", tz);
241 timezones0.put("America/Iqaluit", tz);
242 timezones0.put("America/Jamaica", tz);
243 timezones0.put("America/Lima", tz);
244 timezones0.put("America/Panama", tz);
245 timezones0.put("America/Pangnirtung", tz);
246 timezones0.put("America/Port-au-Prince", tz);
247 timezones0.put("America/Porto_Acre", tz);
248 timezones0.put("America/Rankin_Inlet", tz);
249 tz = new SimpleTimeZone
250 (-5000 * 3600, "EST",
251 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
252 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
253 timezones0.put("EST", tz);
254 timezones0.put("EST5EDT", tz);
255 timezones0.put("America/Detroit", tz);
256 timezones0.put("America/Kentucky/Louisville", tz);
257 timezones0.put("America/Kentucky/Monticello", tz);
258 timezones0.put("America/Louisville", tz);
259 timezones0.put("America/Montreal", tz);
260 timezones0.put("America/Nassau", tz);
261 timezones0.put("America/New_York", tz);
262 timezones0.put("America/Nipigon", tz);
263 timezones0.put("America/Thunder_Bay", tz);
264 tz = new SimpleTimeZone(-4000 * 3600, "PRT");
265 timezones0.put("PRT", tz);
266 timezones0.put("America/Anguilla", tz);
267 timezones0.put("America/Antigua", tz);
268 timezones0.put("America/Aruba", tz);
269 timezones0.put("America/Barbados", tz);
270 timezones0.put("America/Boa_Vista", tz);
271 timezones0.put("America/Caracas", tz);
272 timezones0.put("America/Curacao", tz);
273 timezones0.put("America/Dominica", tz);
274 timezones0.put("America/Grenada", tz);
275 timezones0.put("America/Guadeloupe", tz);
276 timezones0.put("America/Guyana", tz);
277 timezones0.put("America/La_Paz", tz);
278 timezones0.put("America/Manaus", tz);
279 timezones0.put("America/Martinique", tz);
280 timezones0.put("America/Montserrat", tz);
281 timezones0.put("America/Port_of_Spain", tz);
282 timezones0.put("America/Porto_Velho", tz);
283 timezones0.put("America/Puerto_Rico", tz);
284 timezones0.put("America/Santo_Domingo", tz);
285 timezones0.put("America/St_Kitts", tz);
286 timezones0.put("America/St_Lucia", tz);
287 timezones0.put("America/St_Thomas", tz);
288 timezones0.put("America/St_Vincent", tz);
289 timezones0.put("America/Tortola", tz);
290 tz = new SimpleTimeZone
291 (-4000 * 3600, "America/Asuncion",
292 Calendar.OCTOBER, 1, Calendar.SUNDAY, 0 * 3600,
293 Calendar.FEBRUARY, -1, Calendar.SUNDAY, 0 * 3600);
294 timezones0.put("America/Asuncion", tz);
295 tz = new SimpleTimeZone
296 (-4000 * 3600, "America/Cuiaba",
297 Calendar.OCTOBER, 2, Calendar.SUNDAY, 0 * 3600,
298 Calendar.FEBRUARY, 3, Calendar.SUNDAY, 0 * 3600);
299 timezones0.put("America/Cuiaba", tz);
300 tz = new SimpleTimeZone
301 (-4000 * 3600, "America/Goose_Bay",
302 Calendar.APRIL, 1, Calendar.SUNDAY, 60000,
303 Calendar.OCTOBER, -1, Calendar.SUNDAY, 60000);
304 timezones0.put("America/Goose_Bay", tz);
305 tz = new SimpleTimeZone
306 (-4000 * 3600, "America/Glace_Bay",
307 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
308 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
309 timezones0.put("America/Glace_Bay", tz);
310 timezones0.put("America/Halifax", tz);
311 timezones0.put("America/Thule", tz);
312 timezones0.put("Atlantic/Bermuda", tz);
313 tz = new SimpleTimeZone
314 (-4000 * 3600, "America/Santiago",
315 Calendar.OCTOBER, 9, -Calendar.SUNDAY, 0 * 3600,
316 Calendar.MARCH, 9, -Calendar.SUNDAY, 0 * 3600);
317 timezones0.put("America/Santiago", tz);
318 timezones0.put("Antarctica/Palmer", tz);
319 tz = new SimpleTimeZone
320 (-4000 * 3600, "Atlantic/Stanley",
321 Calendar.SEPTEMBER, 2, Calendar.SUNDAY, 0 * 3600,
322 Calendar.APRIL, 16, -Calendar.SUNDAY, 0 * 3600);
323 timezones0.put("Atlantic/Stanley", tz);
324 tz = new SimpleTimeZone
325 (-3500 * 3600, "CNT",
326 Calendar.APRIL, 1, Calendar.SUNDAY, 60000,
327 Calendar.OCTOBER, -1, Calendar.SUNDAY, 60000);
328 timezones0.put("CNT", tz);
329 timezones0.put("America/St_Johns", tz);
330 tz = new SimpleTimeZone
331 (-3000 * 3600, "America/Araguaina",
332 Calendar.OCTOBER, 2, Calendar.SUNDAY, 0 * 3600,
333 Calendar.FEBRUARY, 3, Calendar.SUNDAY, 0 * 3600);
334 timezones0.put("America/Araguaina", tz);
335 timezones0.put("America/Sao_Paulo", tz);
336 tz = new SimpleTimeZone(-3000 * 3600, "AGT");
337 timezones0.put("AGT", tz);
338 timezones0.put("America/Belem", tz);
339 timezones0.put("America/Buenos_Aires", tz);
340 timezones0.put("America/Catamarca", tz);
341 timezones0.put("America/Cayenne", tz);
342 timezones0.put("America/Cordoba", tz);
343 timezones0.put("America/Fortaleza", tz);
344 timezones0.put("America/Jujuy", tz);
345 timezones0.put("America/Maceio", tz);
346 timezones0.put("America/Mendoza", tz);
347 timezones0.put("America/Montevideo", tz);
348 timezones0.put("America/Paramaribo", tz);
349 timezones0.put("America/Recife", tz);
350 timezones0.put("America/Rosario", tz);
351 tz = new SimpleTimeZone
352 (-3000 * 3600, "America/Godthab",
353 Calendar.MARCH, 30, -Calendar.SATURDAY, 22000 * 3600,
354 Calendar.OCTOBER, 30, -Calendar.SATURDAY, 22000 * 3600);
355 timezones0.put("America/Godthab", tz);
356 tz = new SimpleTimeZone
357 (-3000 * 3600, "America/Miquelon",
358 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
359 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
360 timezones0.put("America/Miquelon", tz);
361 tz = new SimpleTimeZone(-2000 * 3600, "America/Noronha");
362 timezones0.put("America/Noronha", tz);
363 timezones0.put("Atlantic/South_Georgia", tz);
364 tz = new SimpleTimeZone
365 (-1000 * 3600, "America/Scoresbysund",
366 Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600,
367 Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
368 timezones0.put("America/Scoresbysund", tz);
369 timezones0.put("Atlantic/Azores", tz);
370 tz = new SimpleTimeZone(-1000 * 3600, "Atlantic/Cape_Verde");
371 timezones0.put("Atlantic/Cape_Verde", tz);
372 timezones0.put("Atlantic/Jan_Mayen", tz);
373 tz = new SimpleTimeZone(0 * 3600, "GMT");
374 timezones0.put("GMT", tz);
375 timezones0.put("UTC", tz);
376 timezones0.put("Africa/Abidjan", tz);
377 timezones0.put("Africa/Accra", tz);
378 timezones0.put("Africa/Bamako", tz);
379 timezones0.put("Africa/Banjul", tz);
380 timezones0.put("Africa/Bissau", tz);
381 timezones0.put("Africa/Casablanca", tz);
382 timezones0.put("Africa/Conakry", tz);
383 timezones0.put("Africa/Dakar", tz);
384 timezones0.put("Africa/El_Aaiun", tz);
385 timezones0.put("Africa/Freetown", tz);
386 timezones0.put("Africa/Lome", tz);
387 timezones0.put("Africa/Monrovia", tz);
388 timezones0.put("Africa/Nouakchott", tz);
389 timezones0.put("Africa/Ouagadougou", tz);
390 timezones0.put("Africa/Sao_Tome", tz);
391 timezones0.put("Africa/Timbuktu", tz);
392 timezones0.put("Atlantic/Reykjavik", tz);
393 timezones0.put("Atlantic/St_Helena", tz);
394 timezones0.put("Europe/Belfast", tz);
395 timezones0.put("Europe/Dublin", tz);
396 timezones0.put("Europe/London", tz);
397 tz = new SimpleTimeZone
398 (0 * 3600, "WET",
399 Calendar.MARCH, -1, Calendar.SUNDAY, 1000 * 3600,
400 Calendar.OCTOBER, -1, Calendar.SUNDAY, 1000 * 3600);
401 timezones0.put("WET", tz);
402 timezones0.put("Atlantic/Canary", tz);
403 timezones0.put("Atlantic/Faeroe", tz);
404 timezones0.put("Atlantic/Madeira", tz);
405 timezones0.put("Europe/Lisbon", tz);
406 tz = new SimpleTimeZone(1000 * 3600, "Africa/Algiers");
407 timezones0.put("Africa/Algiers", tz);
408 timezones0.put("Africa/Bangui", tz);
409 timezones0.put("Africa/Brazzaville", tz);
410 timezones0.put("Africa/Douala", tz);
411 timezones0.put("Africa/Kinshasa", tz);
412 timezones0.put("Africa/Lagos", tz);
413 timezones0.put("Africa/Libreville", tz);
414 timezones0.put("Africa/Luanda", tz);
415 timezones0.put("Africa/Malabo", tz);
416 timezones0.put("Africa/Ndjamena", tz);
417 timezones0.put("Africa/Niamey", tz);
418 timezones0.put("Africa/Porto-Novo", tz);
419 timezones0.put("Africa/Tunis", tz);
420 tz = new SimpleTimeZone
421 (1000 * 3600, "Africa/Windhoek",
422 Calendar.SEPTEMBER, 1, Calendar.SUNDAY, 2000 * 3600,
423 Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600);
424 timezones0.put("Africa/Windhoek", tz);
425 tz = new SimpleTimeZone
426 (1000 * 3600, "CET",
427 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
428 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
429 timezones0.put("CET", tz);
430 timezones0.put("ECT", tz);
431 timezones0.put("MET", tz);
432 timezones0.put("Africa/Ceuta", tz);
433 timezones0.put("Arctic/Longyearbyen", tz);
434 timezones0.put("Europe/Amsterdam", tz);
435 timezones0.put("Europe/Andorra", tz);
436 timezones0.put("Europe/Belgrade", tz);
437 timezones0.put("Europe/Berlin", tz);
438 timezones0.put("Europe/Bratislava", tz);
439 timezones0.put("Europe/Brussels", tz);
440 timezones0.put("Europe/Budapest", tz);
441 timezones0.put("Europe/Copenhagen", tz);
442 timezones0.put("Europe/Gibraltar", tz);
443 timezones0.put("Europe/Ljubljana", tz);
444 timezones0.put("Europe/Luxembourg", tz);
445 timezones0.put("Europe/Madrid", tz);
446 timezones0.put("Europe/Malta", tz);
447 timezones0.put("Europe/Monaco", tz);
448 timezones0.put("Europe/Oslo", tz);
449 timezones0.put("Europe/Paris", tz);
450 timezones0.put("Europe/Prague", tz);
451 timezones0.put("Europe/Rome", tz);
452 timezones0.put("Europe/San_Marino", tz);
453 timezones0.put("Europe/Sarajevo", tz);
454 timezones0.put("Europe/Skopje", tz);
455 timezones0.put("Europe/Stockholm", tz);
456 timezones0.put("Europe/Tirane", tz);
457 timezones0.put("Europe/Vaduz", tz);
458 timezones0.put("Europe/Vatican", tz);
459 timezones0.put("Europe/Vienna", tz);
460 timezones0.put("Europe/Warsaw", tz);
461 timezones0.put("Europe/Zagreb", tz);
462 timezones0.put("Europe/Zurich", tz);
463 tz = new SimpleTimeZone
464 (2000 * 3600, "ART",
465 Calendar.APRIL, -1, Calendar.FRIDAY, 0 * 3600,
466 Calendar.SEPTEMBER, -1, Calendar.THURSDAY, 23000 * 3600);
467 timezones0.put("ART", tz);
468 timezones0.put("Africa/Cairo", tz);
469 tz = new SimpleTimeZone(2000 * 3600, "CAT");
470 timezones0.put("CAT", tz);
471 timezones0.put("Africa/Blantyre", tz);
472 timezones0.put("Africa/Bujumbura", tz);
473 timezones0.put("Africa/Gaborone", tz);
474 timezones0.put("Africa/Harare", tz);
475 timezones0.put("Africa/Johannesburg", tz);
476 timezones0.put("Africa/Kigali", tz);
477 timezones0.put("Africa/Lubumbashi", tz);
478 timezones0.put("Africa/Lusaka", tz);
479 timezones0.put("Africa/Maputo", tz);
480 timezones0.put("Africa/Maseru", tz);
481 timezones0.put("Africa/Mbabane", tz);
482 timezones0.put("Africa/Tripoli", tz);
483 timezones0.put("Europe/Riga", tz);
484 timezones0.put("Europe/Tallinn", tz);
485 timezones0.put("Europe/Vilnius", tz);
486 tz = new SimpleTimeZone
487 (2000 * 3600, "Asia/Amman",
488 Calendar.MARCH, -1, Calendar.THURSDAY, 0 * 3600,
489 Calendar.SEPTEMBER, -1, Calendar.THURSDAY, 0 * 3600);
490 timezones0.put("Asia/Amman", tz);
491 tz = new SimpleTimeZone
492 (2000 * 3600, "Asia/Beirut",
493 Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600,
494 Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
495 timezones0.put("Asia/Beirut", tz);
496 tz = new SimpleTimeZone
497 (2000 * 3600, "Asia/Damascus",
498 Calendar.APRIL, 1, 0, 0 * 3600,
499 Calendar.OCTOBER, 1, 0, 0 * 3600);
500 timezones0.put("Asia/Damascus", tz);
501 tz = new SimpleTimeZone
502 (2000 * 3600, "Asia/Gaza",
503 Calendar.APRIL, 3, Calendar.FRIDAY, 0 * 3600,
504 Calendar.OCTOBER, 3, Calendar.FRIDAY, 0 * 3600);
505 timezones0.put("Asia/Gaza", tz);
506 tz = new SimpleTimeZone
507 (2000 * 3600, "Asia/Jerusalem",
508 Calendar.APRIL, 1, 0, 1000 * 3600,
509 Calendar.OCTOBER, 1, 0, 1000 * 3600);
510 timezones0.put("Asia/Jerusalem", tz);
511 tz = new SimpleTimeZone
512 (2000 * 3600, "EET",
513 Calendar.MARCH, -1, Calendar.SUNDAY, 3000 * 3600,
514 Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
515 timezones0.put("EET", tz);
516 timezones0.put("Asia/Istanbul", tz);
517 timezones0.put("Asia/Nicosia", tz);
518 timezones0.put("Europe/Athens", tz);
519 timezones0.put("Europe/Bucharest", tz);
520 timezones0.put("Europe/Chisinau", tz);
521 timezones0.put("Europe/Helsinki", tz);
522 timezones0.put("Europe/Istanbul", tz);
523 timezones0.put("Europe/Kiev", tz);
524 timezones0.put("Europe/Nicosia", tz);
525 timezones0.put("Europe/Simferopol", tz);
526 timezones0.put("Europe/Sofia", tz);
527 timezones0.put("Europe/Uzhgorod", tz);
528 timezones0.put("Europe/Zaporozhye", tz);
529 tz = new SimpleTimeZone
530 (2000 * 3600, "Europe/Kaliningrad",
531 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
532 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
533 timezones0.put("Europe/Kaliningrad", tz);
534 timezones0.put("Europe/Minsk", tz);
535 tz = new SimpleTimeZone
536 (3000 * 3600, "Asia/Baghdad",
537 Calendar.APRIL, 1, 0, 3000 * 3600,
538 Calendar.OCTOBER, 1, 0, 3000 * 3600);
539 timezones0.put("Asia/Baghdad", tz);
540 tz = new SimpleTimeZone
541 (3000 * 3600, "Europe/Moscow",
542 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
543 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
544 timezones0.put("Europe/Moscow", tz);
545 timezones0.put("Europe/Tiraspol", tz);
546 tz = new SimpleTimeZone(3000 * 3600, "EAT");
547 timezones0.put("EAT", tz);
548 timezones0.put("Africa/Addis_Ababa", tz);
549 timezones0.put("Africa/Asmera", tz);
550 timezones0.put("Africa/Dar_es_Salaam", tz);
551 timezones0.put("Africa/Djibouti", tz);
552 timezones0.put("Africa/Kampala", tz);
553 timezones0.put("Africa/Khartoum", tz);
554 timezones0.put("Africa/Mogadishu", tz);
555 timezones0.put("Africa/Nairobi", tz);
556 timezones0.put("Antarctica/Syowa", tz);
557 timezones0.put("Asia/Aden", tz);
558 timezones0.put("Asia/Bahrain", tz);
559 timezones0.put("Asia/Kuwait", tz);
560 timezones0.put("Asia/Qatar", tz);
561 timezones0.put("Asia/Riyadh", tz);
562 timezones0.put("Indian/Antananarivo", tz);
563 timezones0.put("Indian/Comoro", tz);
564 timezones0.put("Indian/Mayotte", tz);
565 tz = new SimpleTimeZone(3500 * 3600, "Asia/Tehran");
566 timezones0.put("Asia/Tehran", tz);
567 tz = new SimpleTimeZone
568 (4000 * 3600, "Asia/Baku",
569 Calendar.MARCH, -1, Calendar.SUNDAY, 1000 * 3600,
570 Calendar.OCTOBER, -1, Calendar.SUNDAY, 1000 * 3600);
571 timezones0.put("Asia/Baku", tz);
572 tz = new SimpleTimeZone
573 (4000 * 3600, "Asia/Aqtau",
574 Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600,
575 Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
576 timezones0.put("Asia/Aqtau", tz);
577 timezones0.put("Asia/Tbilisi", tz);
578 tz = new SimpleTimeZone
579 (4000 * 3600, "Asia/Yerevan",
580 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
581 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
582 timezones0.put("Asia/Yerevan", tz);
583 timezones0.put("Europe/Samara", tz);
584 tz = new SimpleTimeZone(4000 * 3600, "NET");
585 timezones0.put("NET", tz);
586 timezones0.put("Asia/Dubai", tz);
587 timezones0.put("Asia/Muscat", tz);
588 timezones0.put("Indian/Mahe", tz);
589 timezones0.put("Indian/Mauritius", tz);
590 timezones0.put("Indian/Reunion", tz);
591 tz = new SimpleTimeZone(4500 * 3600, "Asia/Kabul");
592 timezones0.put("Asia/Kabul", tz);
593 tz = new SimpleTimeZone
594 (5000 * 3600, "Asia/Aqtobe",
595 Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600,
596 Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
597 timezones0.put("Asia/Aqtobe", tz);
598 tz = new SimpleTimeZone
599 (5000 * 3600, "Asia/Bishkek",
600 Calendar.MARCH, -1, Calendar.SUNDAY, 2500 * 3600,
601 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2500 * 3600);
602 timezones0.put("Asia/Bishkek", tz);
603 tz = new SimpleTimeZone
604 (5000 * 3600, "Asia/Yekaterinburg",
605 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
606 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
607 timezones0.put("Asia/Yekaterinburg", tz);
608 tz = new SimpleTimeZone(5000 * 3600, "PLT");
609 timezones0.put("PLT", tz);
610 timezones0.put("Asia/Ashgabat", tz);
611 timezones0.put("Asia/Dushanbe", tz);
612 timezones0.put("Asia/Karachi", tz);
613 timezones0.put("Asia/Samarkand", tz);
614 timezones0.put("Asia/Tashkent", tz);
615 timezones0.put("Indian/Chagos", tz);
616 timezones0.put("Indian/Kerguelen", tz);
617 timezones0.put("Indian/Maldives", tz);
618 tz = new SimpleTimeZone(5500 * 3600, "IST");
619 timezones0.put("IST", tz);
620 timezones0.put("Asia/Calcutta", tz);
621 tz = new SimpleTimeZone(5750 * 3600, "Asia/Katmandu");
622 timezones0.put("Asia/Katmandu", tz);
623 tz = new SimpleTimeZone(6000 * 3600, "BST");
624 timezones0.put("BST", tz);
625 timezones0.put("Antarctica/Mawson", tz);
626 timezones0.put("Asia/Colombo", tz);
627 timezones0.put("Asia/Dhaka", tz);
628 timezones0.put("Asia/Thimphu", tz);
629 tz = new SimpleTimeZone
630 (6000 * 3600, "Asia/Almaty",
631 Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600,
632 Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
633 timezones0.put("Asia/Almaty", tz);
634 tz = new SimpleTimeZone
635 (6000 * 3600, "Asia/Novosibirsk",
636 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
637 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
638 timezones0.put("Asia/Novosibirsk", tz);
639 timezones0.put("Asia/Omsk", tz);
640 tz = new SimpleTimeZone(6500 * 3600, "Asia/Rangoon");
641 timezones0.put("Asia/Rangoon", tz);
642 timezones0.put("Indian/Cocos", tz);
643 tz = new SimpleTimeZone(7000 * 3600, "VST");
644 timezones0.put("VST", tz);
645 timezones0.put("Antarctica/Davis", tz);
646 timezones0.put("Asia/Bangkok", tz);
647 timezones0.put("Asia/Hovd", tz);
648 timezones0.put("Asia/Jakarta", tz);
649 timezones0.put("Asia/Phnom_Penh", tz);
650 timezones0.put("Asia/Saigon", tz);
651 timezones0.put("Asia/Vientiane", tz);
652 timezones0.put("Indian/Christmas", tz);
653 tz = new SimpleTimeZone
654 (7000 * 3600, "Asia/Krasnoyarsk",
655 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
656 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
657 timezones0.put("Asia/Krasnoyarsk", tz);
658 tz = new SimpleTimeZone(8000 * 3600, "CTT");
659 timezones0.put("CTT", tz);
660 timezones0.put("Antarctica/Casey", tz);
661 timezones0.put("Asia/Brunei", tz);
662 timezones0.put("Asia/Chungking", tz);
663 timezones0.put("Asia/Harbin", tz);
664 timezones0.put("Asia/Hong_Kong", tz);
665 timezones0.put("Asia/Kashgar", tz);
666 timezones0.put("Asia/Kuala_Lumpur", tz);
667 timezones0.put("Asia/Kuching", tz);
668 timezones0.put("Asia/Macao", tz);
669 timezones0.put("Asia/Manila", tz);
670 timezones0.put("Asia/Shanghai", tz);
671 timezones0.put("Asia/Singapore", tz);
672 timezones0.put("Asia/Taipei", tz);
673 timezones0.put("Asia/Ujung_Pandang", tz);
674 timezones0.put("Asia/Ulaanbaatar", tz);
675 timezones0.put("Asia/Urumqi", tz);
676 timezones0.put("Australia/Perth", tz);
677 tz = new SimpleTimeZone
678 (8000 * 3600, "Asia/Irkutsk",
679 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
680 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
681 timezones0.put("Asia/Irkutsk", tz);
682 tz = new SimpleTimeZone(9000 * 3600, "JST");
683 timezones0.put("JST", tz);
684 timezones0.put("Asia/Dili", tz);
685 timezones0.put("Asia/Jayapura", tz);
686 timezones0.put("Asia/Pyongyang", tz);
687 timezones0.put("Asia/Seoul", tz);
688 timezones0.put("Asia/Tokyo", tz);
689 timezones0.put("Pacific/Palau", tz);
690 tz = new SimpleTimeZone
691 (9000 * 3600, "Asia/Yakutsk",
692 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
693 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
694 timezones0.put("Asia/Yakutsk", tz);
695 tz = new SimpleTimeZone
696 (9500 * 3600, "Australia/Adelaide",
697 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600,
698 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600);
699 timezones0.put("Australia/Adelaide", tz);
700 timezones0.put("Australia/Broken_Hill", tz);
701 tz = new SimpleTimeZone(9500 * 3600, "ACT");
702 timezones0.put("ACT", tz);
703 timezones0.put("Australia/Darwin", tz);
704 tz = new SimpleTimeZone(10000 * 3600, "Antarctica/DumontDUrville");
705 timezones0.put("Antarctica/DumontDUrville", tz);
706 timezones0.put("Australia/Brisbane", tz);
707 timezones0.put("Australia/Lindeman", tz);
708 timezones0.put("Pacific/Guam", tz);
709 timezones0.put("Pacific/Port_Moresby", tz);
710 timezones0.put("Pacific/Saipan", tz);
711 timezones0.put("Pacific/Truk", tz);
712 timezones0.put("Pacific/Yap", tz);
713 tz = new SimpleTimeZone
714 (10000 * 3600, "Asia/Vladivostok",
715 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
716 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
717 timezones0.put("Asia/Vladivostok", tz);
718 tz = new SimpleTimeZone
719 (10000 * 3600, "Australia/Hobart",
720 Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600,
721 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600);
722 timezones0.put("Australia/Hobart", tz);
723 tz = new SimpleTimeZone
724 (10000 * 3600, "AET",
725 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600,
726 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600);
727 timezones0.put("AET", tz);
728 timezones0.put("Australia/Melbourne", tz);
729 timezones0.put("Australia/Sydney", tz);
730 tz = new SimpleTimeZone
731 (10500 * 3600, "Australia/Lord_Howe",
732 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600,
733 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, 500 * 3600);
734 timezones0.put("Australia/Lord_Howe", tz);
735 tz = new SimpleTimeZone
736 (11000 * 3600, "Asia/Magadan",
737 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
738 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
739 timezones0.put("Asia/Magadan", tz);
740 tz = new SimpleTimeZone(11000 * 3600, "SST");
741 timezones0.put("SST", tz);
742 timezones0.put("Pacific/Efate", tz);
743 timezones0.put("Pacific/Guadalcanal", tz);
744 timezones0.put("Pacific/Kosrae", tz);
745 timezones0.put("Pacific/Noumea", tz);
746 timezones0.put("Pacific/Ponape", tz);
747 tz = new SimpleTimeZone(11500 * 3600, "Pacific/Norfolk");
748 timezones0.put("Pacific/Norfolk", tz);
749 tz = new SimpleTimeZone
750 (12000 * 3600, "NST",
751 Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600,
752 Calendar.MARCH, 3, Calendar.SUNDAY, 2000 * 3600);
753 timezones0.put("NST", tz);
754 timezones0.put("Antarctica/McMurdo", tz);
755 timezones0.put("Antarctica/South_Pole", tz);
756 timezones0.put("Pacific/Auckland", tz);
757 tz = new SimpleTimeZone
758 (12000 * 3600, "Asia/Anadyr",
759 Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
760 Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
761 timezones0.put("Asia/Anadyr", tz);
762 timezones0.put("Asia/Kamchatka", tz);
763 tz = new SimpleTimeZone(12000 * 3600, "Pacific/Fiji");
764 timezones0.put("Pacific/Fiji", tz);
765 timezones0.put("Pacific/Funafuti", tz);
766 timezones0.put("Pacific/Kwajalein", tz);
767 timezones0.put("Pacific/Majuro", tz);
768 timezones0.put("Pacific/Nauru", tz);
769 timezones0.put("Pacific/Tarawa", tz);
770 timezones0.put("Pacific/Wake", tz);
771 timezones0.put("Pacific/Wallis", tz);
772 tz = new SimpleTimeZone
773 (12750 * 3600, "Pacific/Chatham",
774 Calendar.OCTOBER, 1, Calendar.SUNDAY, 2750 * 3600,
775 Calendar.MARCH, 3, Calendar.SUNDAY, 2750 * 3600);
776 timezones0.put("Pacific/Chatham", tz);
777 tz = new SimpleTimeZone(13000 * 3600, "Pacific/Enderbury");
778 timezones0.put("Pacific/Enderbury", tz);
779 timezones0.put("Pacific/Tongatapu", tz);
780 tz = new SimpleTimeZone(14000 * 3600, "Pacific/Kiritimati");
781 timezones0.put("Pacific/Kiritimati", tz);
783 return timezones0;
787 /* This method returns us a time zone id string which is in the
788 form <standard zone name><GMT offset><daylight time zone name>.
789 The GMT offset is in seconds, except where it is evenly divisible
790 by 3600, then it is in hours. If the zone does not observe
791 daylight time, then the daylight zone name is omitted. Examples:
792 in Chicago, the timezone would be CST6CDT. In Indianapolis
793 (which does not have Daylight Savings Time) the string would
794 be EST5
796 private static native String getDefaultTimeZoneId();
799 * Gets the time zone offset, for current date, modified in case of
800 * daylight savings. This is the offset to add to UTC to get the local
801 * time.
802 * @param era the era of the given date
803 * @param year the year of the given date
804 * @param month the month of the given date, 0 for January.
805 * @param day the day of month
806 * @param dayOfWeek the day of week
807 * @param milliseconds the millis in the day (in local standard time)
808 * @return the time zone offset in milliseconds.
810 public abstract int getOffset(int era, int year, int month,
811 int day, int dayOfWeek, int milliseconds);
814 * Get the time zone offset for the specified date, modified in case of
815 * daylight savings. This is the offset to add to UTC to get the local
816 * time.
817 * @param date the date represented in millisecends
818 * since January 1, 1970 00:00:00 GMT.
819 * @since 1.4
821 public int getOffset(long date)
823 return (inDaylightTime(new Date(date))
824 ? getRawOffset() + getDSTSavings()
825 : getRawOffset());
829 * Gets the time zone offset, ignoring daylight savings. This is
830 * the offset to add to UTC to get the local time.
831 * @return the time zone offset in milliseconds.
833 public abstract int getRawOffset();
836 * Sets the time zone offset, ignoring daylight savings. This is
837 * the offset to add to UTC to get the local time.
838 * @param offsetMillis the time zone offset to GMT.
840 public abstract void setRawOffset(int offsetMillis);
843 * Gets the identifier of this time zone. For instance, PST for
844 * Pacific Standard Time.
845 * @returns the ID of this time zone.
847 public String getID()
849 return ID;
853 * Sets the identifier of this time zone. For instance, PST for
854 * Pacific Standard Time.
855 * @param id the new time zone ID.
857 public void setID(String id)
859 this.ID = id;
863 * This method returns a string name of the time zone suitable
864 * for displaying to the user. The string returned will be the long
865 * description of the timezone in the current locale. The name
866 * displayed will assume daylight savings time is not in effect.
868 * @return The name of the time zone.
870 public final String getDisplayName()
872 return (getDisplayName(false, LONG, Locale.getDefault()));
876 * This method returns a string name of the time zone suitable
877 * for displaying to the user. The string returned will be the long
878 * description of the timezone in the specified locale. The name
879 * displayed will assume daylight savings time is not in effect.
881 * @param locale The locale for this timezone name.
883 * @return The name of the time zone.
885 public final String getDisplayName(Locale locale)
887 return (getDisplayName(false, LONG, locale));
891 * This method returns a string name of the time zone suitable
892 * for displaying to the user. The string returned will be of the
893 * specified type in the current locale.
895 * @param dst Whether or not daylight savings time is in effect.
896 * @param style <code>LONG</code> for a long name, <code>SHORT</code> for
897 * a short abbreviation.
899 * @return The name of the time zone.
901 public final String getDisplayName(boolean dst, int style)
903 return (getDisplayName(dst, style, Locale.getDefault()));
908 * This method returns a string name of the time zone suitable
909 * for displaying to the user. The string returned will be of the
910 * specified type in the specified locale.
912 * @param dst Whether or not daylight savings time is in effect.
913 * @param style <code>LONG</code> for a long name, <code>SHORT</code> for
914 * a short abbreviation.
915 * @param locale The locale for this timezone name.
917 * @return The name of the time zone.
919 public String getDisplayName(boolean dst, int style, Locale locale)
921 DateFormatSymbols dfs;
924 dfs = new DateFormatSymbols(locale);
926 // The format of the value returned is defined by us.
927 String[][]zoneinfo = dfs.getZoneStrings();
928 for (int i = 0; i < zoneinfo.length; i++)
930 if (zoneinfo[i][0].equals(getID()))
932 if (!dst)
934 if (style == SHORT)
935 return (zoneinfo[i][2]);
936 else
937 return (zoneinfo[i][1]);
939 else
941 if (style == SHORT)
942 return (zoneinfo[i][4]);
943 else
944 return (zoneinfo[i][3]);
949 catch (MissingResourceException e)
953 return getDefaultDisplayName(dst);
956 private String getDefaultDisplayName(boolean dst)
958 int offset = getRawOffset();
959 if (dst && this instanceof SimpleTimeZone)
961 // ugly, but this is a design failure of the API:
962 // getDisplayName takes a dst parameter even though
963 // TimeZone knows nothing about daylight saving offsets.
964 offset += ((SimpleTimeZone) this).getDSTSavings();
967 StringBuffer sb = new StringBuffer(9);
968 sb.append("GMT");
969 sb.append(offset >= 0 ? '+' : '-');
971 offset = Math.abs(offset) / (1000 * 60);
972 int hours = offset / 60;
973 int minutes = offset % 60;
975 sb.append((char) ('0' + hours / 10)).append((char) ('0' + hours % 10));
976 sb.append(':');
977 sb.append((char) ('0' + minutes / 10)).append((char) ('0' + minutes % 10));
978 return sb.toString();
981 /**
982 * Returns true, if this time zone uses Daylight Savings Time.
984 public abstract boolean useDaylightTime();
987 * Returns true, if the given date is in Daylight Savings Time in this
988 * time zone.
989 * @param date the given Date.
991 public abstract boolean inDaylightTime(Date date);
994 * Gets the daylight savings offset. This is a positive offset in
995 * milliseconds with respect to standard time. Typically this
996 * is one hour, but for some time zones this may be half an our.
997 * <p>The default implementation returns 3600000 milliseconds
998 * (one hour) if the time zone uses daylight savings time
999 * (as specified by {@link #useDaylightTime()}), otherwise
1000 * it returns 0.
1001 * @return the daylight savings offset in milliseconds.
1002 * @since 1.4
1004 public int getDSTSavings ()
1006 return useDaylightTime () ? 3600000 : 0;
1010 * Gets the TimeZone for the given ID.
1011 * @param ID the time zone identifier.
1012 * @return The time zone for the identifier or GMT, if no such time
1013 * zone exists.
1015 // FIXME: XXX: JCL indicates this and other methods are synchronized.
1016 public static TimeZone getTimeZone(String ID)
1018 // First check timezones hash
1019 TimeZone tz = (TimeZone) timezones().get(ID);
1020 if (tz != null)
1022 if (tz.getID().equals(ID))
1023 return tz;
1025 // We always return a timezone with the requested ID.
1026 // This is the same behaviour as with JDK1.2.
1027 tz = (TimeZone) tz.clone();
1028 tz.setID(ID);
1029 // We also save the alias, so that we return the same
1030 // object again if getTimeZone is called with the same
1031 // alias.
1032 timezones().put(ID, tz);
1033 return tz;
1036 // See if the ID is really a GMT offset form.
1037 // Note that GMT is in the table so we know it is different.
1038 if (ID.startsWith("GMT"))
1040 int pos = 3;
1041 int offset_direction = 1;
1043 if (ID.charAt(pos) == '-')
1045 offset_direction = -1;
1046 pos++;
1048 else if (ID.charAt(pos) == '+')
1050 pos++;
1055 int hour, minute;
1057 String offset_str = ID.substring(pos);
1058 int idx = offset_str.indexOf(":");
1059 if (idx != -1)
1061 hour = Integer.parseInt(offset_str.substring(0, idx));
1062 minute = Integer.parseInt(offset_str.substring(idx + 1));
1064 else
1066 int offset_length = offset_str.length();
1067 if (offset_length <= 2)
1069 // Only hour
1070 hour = Integer.parseInt(offset_str);
1071 minute = 0;
1073 else
1075 // hour and minute, not separated by colon
1076 hour = Integer.parseInt
1077 (offset_str.substring(0, offset_length - 2));
1078 minute = Integer.parseInt
1079 (offset_str.substring(offset_length - 2));
1083 return new SimpleTimeZone((hour * (60 * 60 * 1000) +
1084 minute * (60 * 1000))
1085 * offset_direction, ID);
1087 catch (NumberFormatException e)
1092 // Finally, return GMT per spec
1093 return getTimeZone("GMT");
1097 * Gets the available IDs according to the given time zone
1098 * offset.
1099 * @param rawOffset the given time zone GMT offset.
1100 * @return An array of IDs, where the time zone has the specified GMT
1101 * offset. For example <code>{"Phoenix", "Denver"}</code>, since both have
1102 * GMT-07:00, but differ in daylight savings behaviour.
1104 public static String[] getAvailableIDs(int rawOffset)
1106 int count = 0;
1107 Iterator iter = timezones().entrySet().iterator();
1108 while (iter.hasNext())
1110 // Don't iterate the values, since we want to count
1111 // doubled values (aliases)
1112 Map.Entry entry = (Map.Entry) iter.next();
1113 if (((TimeZone) entry.getValue()).getRawOffset() == rawOffset)
1114 count++;
1117 String[] ids = new String[count];
1118 count = 0;
1119 iter = timezones().entrySet().iterator();
1120 while (iter.hasNext())
1122 Map.Entry entry = (Map.Entry) iter.next();
1123 if (((TimeZone) entry.getValue()).getRawOffset() == rawOffset)
1124 ids[count++] = (String) entry.getKey();
1126 return ids;
1130 * Gets all available IDs.
1131 * @return An array of all supported IDs.
1133 public static String[] getAvailableIDs()
1135 return (String[])
1136 timezones().keySet().toArray(new String[timezones().size()]);
1140 * Returns the time zone under which the host is running. This
1141 * can be changed with setDefault.
1142 * @return the time zone for this host.
1143 * @see #setDefault
1145 public static TimeZone getDefault()
1147 return defaultZone();
1150 public static void setDefault(TimeZone zone)
1152 defaultZone0 = zone;
1156 * Test if the other time zone uses the same rule and only
1157 * possibly differs in ID. This implementation for this particular
1158 * class will return true if the raw offsets are identical. Subclasses
1159 * should override this method if they use daylight savings.
1160 * @return true if this zone has the same raw offset
1162 public boolean hasSameRules(TimeZone other)
1164 return other.getRawOffset() == getRawOffset();
1168 * Returns a clone of this object. I can't imagine, why this is
1169 * useful for a time zone.
1171 public Object clone()
1175 return super.clone();
1177 catch (CloneNotSupportedException ex)
1179 return null;