TimeZone.java 41 KB

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