TimeZone.java 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782
  1. /* java.util.TimeZone
  2. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2012
  3. Free Software Foundation, Inc.
  4. This file is part of GNU Classpath.
  5. GNU Classpath is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. GNU Classpath is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Classpath; see the file COPYING. If not, write to the
  15. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA.
  17. Linking this library statically or dynamically with other modules is
  18. making a combined work based on this library. Thus, the terms and
  19. conditions of the GNU General Public License cover the whole
  20. combination.
  21. As a special exception, the copyright holders of this library give you
  22. permission to link this library with independent modules to produce an
  23. executable, regardless of the license terms of these independent
  24. modules, and to copy and distribute the resulting executable under
  25. terms of your choice, provided that you also meet, for each linked
  26. independent module, the terms and conditions of the license of that
  27. module. An independent module is a module which is not derived from
  28. or based on this library. If you modify this library, you may extend
  29. this exception to your version of the library, but you are not
  30. obligated to do so. If you do not wish to do so, delete this
  31. exception statement from your version. */
  32. package java.util;
  33. import gnu.classpath.SystemProperties;
  34. import gnu.java.lang.CPStringBuilder;
  35. import gnu.java.util.ZoneInfo;
  36. import java.io.File;
  37. import java.security.AccessController;
  38. import java.security.PrivilegedAction;
  39. import java.text.DateFormatSymbols;
  40. /**
  41. * This class represents a time zone offset and handles daylight savings.
  42. *
  43. * You can get the default time zone with <code>getDefault</code>.
  44. * This represents the time zone where program is running.
  45. *
  46. * Another way to create a time zone is <code>getTimeZone</code>, where
  47. * you can give an identifier as parameter. For instance, the identifier
  48. * of the Central European Time zone is "CET".
  49. *
  50. * With the <code>getAvailableIDs</code> method, you can get all the
  51. * supported time zone identifiers.
  52. *
  53. * @see Calendar
  54. * @see SimpleTimeZone
  55. * @author Jochen Hoenicke
  56. */
  57. public abstract class TimeZone implements java.io.Serializable, Cloneable
  58. {
  59. /**
  60. * Constant used to indicate that a short timezone abbreviation should
  61. * be returned, such as "EST"
  62. */
  63. public static final int SHORT = 0;
  64. /**
  65. * Constant used to indicate that a long timezone name should be
  66. * returned, such as "Eastern Standard Time".
  67. */
  68. public static final int LONG = 1;
  69. /**
  70. * The time zone identifier, e.g. PST.
  71. */
  72. private String ID;
  73. /**
  74. * The default time zone, as returned by getDefault.
  75. */
  76. private static TimeZone defaultZone0;
  77. /**
  78. * Tries to get the default TimeZone for this system if not already
  79. * set. It will call <code>getDefaultTimeZone(String)</code> with
  80. * the result of <code>System.getProperty("user.timezone")</code>.
  81. * If that fails it calls <code>VMTimeZone.getDefaultTimeZoneId()</code>.
  82. * If that also fails GMT is returned.
  83. */
  84. private static synchronized TimeZone defaultZone()
  85. {
  86. /* Look up default timezone */
  87. if (defaultZone0 == null)
  88. {
  89. defaultZone0 = AccessController.doPrivileged
  90. (new PrivilegedAction<TimeZone>()
  91. {
  92. public TimeZone run()
  93. {
  94. TimeZone zone = null;
  95. // Prefer System property user.timezone.
  96. String tzid = System.getProperty("user.timezone");
  97. if (tzid != null && !tzid.equals(""))
  98. zone = getDefaultTimeZone(tzid);
  99. // Try platfom specific way.
  100. if (zone == null)
  101. zone = VMTimeZone.getDefaultTimeZoneId();
  102. // Fall back on GMT.
  103. if (zone == null)
  104. zone = getTimeZone ("GMT");
  105. return zone;
  106. }
  107. });
  108. }
  109. return defaultZone0;
  110. }
  111. private static final long serialVersionUID = 3581463369166924961L;
  112. /**
  113. * Flag whether zoneinfo data should be used,
  114. * otherwise builtin timezone data will be provided.
  115. */
  116. private static String zoneinfo_dir;
  117. /**
  118. * Cached copy of getAvailableIDs().
  119. */
  120. private static String[] availableIDs = null;
  121. /**
  122. * JDK 1.1.x compatibility aliases.
  123. */
  124. private static HashMap<String,String> aliases0;
  125. /**
  126. * HashMap for timezones by ID.
  127. */
  128. private static HashMap<String,TimeZone> timezones0;
  129. /* initialize this static field lazily to overhead if
  130. * it is not needed:
  131. */
  132. // Package-private to avoid a trampoline.
  133. static HashMap<String,TimeZone> timezones()
  134. {
  135. if (timezones0 == null)
  136. {
  137. HashMap<String,TimeZone> timezones = new HashMap<String,TimeZone>();
  138. timezones0 = timezones;
  139. zoneinfo_dir = SystemProperties.getProperty("gnu.java.util.zoneinfo.dir");
  140. if (zoneinfo_dir != null && !new File(zoneinfo_dir).isDirectory())
  141. zoneinfo_dir = null;
  142. if (zoneinfo_dir != null)
  143. {
  144. aliases0 = new HashMap<String,String>();
  145. // These deprecated aliases for JDK 1.1.x compatibility
  146. // should take precedence over data files read from
  147. // /usr/share/zoneinfo.
  148. aliases0.put("ACT", "Australia/Darwin");
  149. aliases0.put("AET", "Australia/Sydney");
  150. aliases0.put("AGT", "America/Argentina/Buenos_Aires");
  151. aliases0.put("ART", "Africa/Cairo");
  152. aliases0.put("AST", "America/Juneau");
  153. aliases0.put("BST", "Asia/Colombo");
  154. aliases0.put("CAT", "Africa/Gaborone");
  155. aliases0.put("CNT", "America/St_Johns");
  156. aliases0.put("CST", "CST6CDT");
  157. aliases0.put("CTT", "Asia/Brunei");
  158. aliases0.put("EAT", "Indian/Comoro");
  159. aliases0.put("ECT", "CET");
  160. aliases0.put("EST", "EST5EDT");
  161. aliases0.put("EST5", "EST5EDT");
  162. aliases0.put("IET", "EST5EDT");
  163. aliases0.put("IST", "Asia/Calcutta");
  164. aliases0.put("JST", "Asia/Seoul");
  165. aliases0.put("MIT", "Pacific/Niue");
  166. aliases0.put("MST", "MST7MDT");
  167. aliases0.put("MST7", "MST7MDT");
  168. aliases0.put("NET", "Indian/Mauritius");
  169. aliases0.put("NST", "Pacific/Auckland");
  170. aliases0.put("PLT", "Indian/Kerguelen");
  171. aliases0.put("PNT", "MST7MDT");
  172. aliases0.put("PRT", "America/Anguilla");
  173. aliases0.put("PST", "PST8PDT");
  174. aliases0.put("SST", "Pacific/Ponape");
  175. aliases0.put("VST", "Asia/Bangkok");
  176. return timezones;
  177. }
  178. TimeZone tz;
  179. // Automatically generated by scripts/timezones.pl
  180. // XXX - Should we read this data from a file?
  181. tz = new SimpleTimeZone(-11000 * 3600, "MIT");
  182. timezones0.put("MIT", tz);
  183. timezones0.put("Pacific/Apia", tz);
  184. timezones0.put("Pacific/Midway", tz);
  185. timezones0.put("Pacific/Niue", tz);
  186. timezones0.put("Pacific/Pago_Pago", tz);
  187. tz = new SimpleTimeZone
  188. (-10000 * 3600, "America/Adak",
  189. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600,
  190. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2000 * 3600);
  191. timezones0.put("America/Adak", tz);
  192. tz = new SimpleTimeZone(-10000 * 3600, "HST");
  193. timezones0.put("HST", tz);
  194. timezones0.put("Pacific/Fakaofo", tz);
  195. timezones0.put("Pacific/Honolulu", tz);
  196. timezones0.put("Pacific/Johnston", tz);
  197. timezones0.put("Pacific/Rarotonga", tz);
  198. timezones0.put("Pacific/Tahiti", tz);
  199. tz = new SimpleTimeZone(-9500 * 3600, "Pacific/Marquesas");
  200. timezones0.put("Pacific/Marquesas", tz);
  201. tz = new SimpleTimeZone
  202. (-9000 * 3600, "AST",
  203. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600,
  204. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2000 * 3600);
  205. timezones0.put("AST", tz);
  206. timezones0.put("America/Anchorage", tz);
  207. timezones0.put("America/Juneau", tz);
  208. timezones0.put("America/Nome", tz);
  209. timezones0.put("America/Yakutat", tz);
  210. tz = new SimpleTimeZone(-9000 * 3600, "Pacific/Gambier");
  211. timezones0.put("Pacific/Gambier", tz);
  212. tz = new SimpleTimeZone
  213. (-8000 * 3600, "America/Tijuana",
  214. Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
  215. Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
  216. timezones0.put("America/Tijuana", tz);
  217. tz = new SimpleTimeZone
  218. (-8000 * 3600, "PST",
  219. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600,
  220. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2000 * 3600);
  221. timezones0.put("PST", tz);
  222. timezones0.put("PST8PDT", tz);
  223. timezones0.put("America/Dawson", tz);
  224. timezones0.put("America/Los_Angeles", tz);
  225. timezones0.put("America/Vancouver", tz);
  226. timezones0.put("America/Whitehorse", tz);
  227. timezones0.put("US/Pacific-New", tz);
  228. tz = new SimpleTimeZone(-8000 * 3600, "Pacific/Pitcairn");
  229. timezones0.put("Pacific/Pitcairn", tz);
  230. tz = new SimpleTimeZone
  231. (-7000 * 3600, "America/Chihuahua",
  232. Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
  233. Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
  234. timezones0.put("America/Chihuahua", tz);
  235. timezones0.put("America/Mazatlan", tz);
  236. tz = new SimpleTimeZone(-7000 * 3600, "MST7");
  237. timezones0.put("MST7", tz);
  238. timezones0.put("PNT", tz);
  239. timezones0.put("America/Dawson_Creek", tz);
  240. timezones0.put("America/Hermosillo", tz);
  241. timezones0.put("America/Phoenix", tz);
  242. tz = new SimpleTimeZone
  243. (-7000 * 3600, "MST",
  244. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600,
  245. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2000 * 3600);
  246. timezones0.put("MST", tz);
  247. timezones0.put("MST7MDT", tz);
  248. timezones0.put("America/Boise", tz);
  249. timezones0.put("America/Cambridge_Bay", tz);
  250. timezones0.put("America/Denver", tz);
  251. timezones0.put("America/Edmonton", tz);
  252. timezones0.put("America/Inuvik", tz);
  253. timezones0.put("America/Shiprock", tz);
  254. timezones0.put("America/Yellowknife", tz);
  255. tz = new SimpleTimeZone
  256. (-6000 * 3600, "America/Cancun",
  257. Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600,
  258. Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
  259. timezones0.put("America/Cancun", tz);
  260. timezones0.put("America/Merida", tz);
  261. timezones0.put("America/Mexico_City", tz);
  262. timezones0.put("America/Monterrey", tz);
  263. tz = new SimpleTimeZone(-6000 * 3600, "America/Belize");
  264. timezones0.put("America/Belize", tz);
  265. timezones0.put("America/Costa_Rica", tz);
  266. timezones0.put("America/El_Salvador", tz);
  267. timezones0.put("America/Guatemala", tz);
  268. timezones0.put("America/Managua", tz);
  269. timezones0.put("America/Regina", tz);
  270. timezones0.put("America/Swift_Current", tz);
  271. timezones0.put("America/Tegucigalpa", tz);
  272. timezones0.put("Pacific/Galapagos", tz);
  273. tz = new SimpleTimeZone
  274. (-6000 * 3600, "CST",
  275. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600,
  276. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2000 * 3600);
  277. timezones0.put("CST", tz);
  278. timezones0.put("CST6CDT", tz);
  279. timezones0.put("America/Chicago", tz);
  280. timezones0.put("America/Indiana/Knox", tz);
  281. timezones0.put("America/Indiana/Petersburg", tz);
  282. timezones0.put("America/Indiana/Vincennes", tz);
  283. timezones0.put("America/Menominee", tz);
  284. timezones0.put("America/North_Dakota/Center", tz);
  285. timezones0.put("America/North_Dakota/New_Salem", tz);
  286. timezones0.put("America/Rainy_River", tz);
  287. timezones0.put("America/Rankin_Inlet", tz);
  288. timezones0.put("America/Winnipeg", tz);
  289. tz = new SimpleTimeZone
  290. (-6000 * 3600, "Pacific/Easter",
  291. Calendar.OCTOBER, 2, Calendar.SATURDAY, 22000 * 3600,
  292. Calendar.MARCH, 2, Calendar.SATURDAY, 22000 * 3600);
  293. timezones0.put("Pacific/Easter", tz);
  294. tz = new SimpleTimeZone(-5000 * 3600, "EST5");
  295. timezones0.put("EST5", tz);
  296. timezones0.put("IET", tz);
  297. timezones0.put("America/Atikokan", tz);
  298. timezones0.put("America/Bogota", tz);
  299. timezones0.put("America/Cayman", tz);
  300. timezones0.put("America/Eirunepe", tz);
  301. timezones0.put("America/Guayaquil", tz);
  302. timezones0.put("America/Jamaica", tz);
  303. timezones0.put("America/Lima", tz);
  304. timezones0.put("America/Panama", tz);
  305. timezones0.put("America/Rio_Branco", tz);
  306. tz = new SimpleTimeZone
  307. (-5000 * 3600, "America/Havana",
  308. Calendar.APRIL, 1, Calendar.SUNDAY, 0 * 3600,
  309. Calendar.OCTOBER, -1, Calendar.SUNDAY, 1000 * 3600);
  310. timezones0.put("America/Havana", tz);
  311. tz = new SimpleTimeZone
  312. (-5000 * 3600, "America/Grand_Turk",
  313. Calendar.APRIL, 1, Calendar.SUNDAY, 0 * 3600,
  314. Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
  315. timezones0.put("America/Grand_Turk", tz);
  316. timezones0.put("America/Port-au-Prince", tz);
  317. tz = new SimpleTimeZone
  318. (-5000 * 3600, "EST",
  319. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600,
  320. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2000 * 3600);
  321. timezones0.put("EST", tz);
  322. timezones0.put("EST5EDT", tz);
  323. timezones0.put("America/Detroit", tz);
  324. timezones0.put("America/Indiana/Indianapolis", tz);
  325. timezones0.put("America/Indiana/Marengo", tz);
  326. timezones0.put("America/Indiana/Vevay", tz);
  327. timezones0.put("America/Iqaluit", tz);
  328. timezones0.put("America/Kentucky/Louisville", tz);
  329. timezones0.put("America/Kentucky/Monticello", tz);
  330. timezones0.put("America/Montreal", tz);
  331. timezones0.put("America/Nassau", tz);
  332. timezones0.put("America/New_York", tz);
  333. timezones0.put("America/Nipigon", tz);
  334. timezones0.put("America/Pangnirtung", tz);
  335. timezones0.put("America/Thunder_Bay", tz);
  336. timezones0.put("America/Toronto", tz);
  337. tz = new SimpleTimeZone
  338. (-4000 * 3600, "America/Asuncion",
  339. Calendar.OCTOBER, 3, Calendar.SUNDAY, 0 * 3600,
  340. Calendar.MARCH, 2, Calendar.SUNDAY, 0 * 3600);
  341. timezones0.put("America/Asuncion", tz);
  342. tz = new SimpleTimeZone(-4000 * 3600, "PRT");
  343. timezones0.put("PRT", tz);
  344. timezones0.put("America/Anguilla", tz);
  345. timezones0.put("America/Antigua", tz);
  346. timezones0.put("America/Aruba", tz);
  347. timezones0.put("America/Barbados", tz);
  348. timezones0.put("America/Blanc-Sablon", tz);
  349. timezones0.put("America/Boa_Vista", tz);
  350. timezones0.put("America/Caracas", tz);
  351. timezones0.put("America/Curacao", tz);
  352. timezones0.put("America/Dominica", tz);
  353. timezones0.put("America/Grenada", tz);
  354. timezones0.put("America/Guadeloupe", tz);
  355. timezones0.put("America/Guyana", tz);
  356. timezones0.put("America/La_Paz", tz);
  357. timezones0.put("America/Manaus", tz);
  358. timezones0.put("America/Martinique", tz);
  359. timezones0.put("America/Montserrat", tz);
  360. timezones0.put("America/Port_of_Spain", tz);
  361. timezones0.put("America/Porto_Velho", tz);
  362. timezones0.put("America/Puerto_Rico", tz);
  363. timezones0.put("America/Santo_Domingo", tz);
  364. timezones0.put("America/St_Kitts", tz);
  365. timezones0.put("America/St_Lucia", tz);
  366. timezones0.put("America/St_Thomas", tz);
  367. timezones0.put("America/St_Vincent", tz);
  368. timezones0.put("America/Tortola", tz);
  369. tz = new SimpleTimeZone
  370. (-4000 * 3600, "America/Campo_Grande",
  371. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0 * 3600,
  372. Calendar.FEBRUARY, -1, Calendar.SUNDAY, 0 * 3600);
  373. timezones0.put("America/Campo_Grande", tz);
  374. timezones0.put("America/Cuiaba", tz);
  375. tz = new SimpleTimeZone
  376. (-4000 * 3600, "America/Goose_Bay",
  377. Calendar.MARCH, 2, Calendar.SUNDAY, 60000,
  378. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 60000);
  379. timezones0.put("America/Goose_Bay", tz);
  380. tz = new SimpleTimeZone
  381. (-4000 * 3600, "America/Glace_Bay",
  382. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600,
  383. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2000 * 3600);
  384. timezones0.put("America/Glace_Bay", tz);
  385. timezones0.put("America/Halifax", tz);
  386. timezones0.put("America/Moncton", tz);
  387. timezones0.put("America/Thule", tz);
  388. timezones0.put("Atlantic/Bermuda", tz);
  389. tz = new SimpleTimeZone
  390. (-4000 * 3600, "America/Santiago",
  391. Calendar.OCTOBER, 9, -Calendar.SUNDAY, 0 * 3600,
  392. Calendar.MARCH, 9, -Calendar.SUNDAY, 0 * 3600);
  393. timezones0.put("America/Santiago", tz);
  394. timezones0.put("Antarctica/Palmer", tz);
  395. tz = new SimpleTimeZone
  396. (-4000 * 3600, "Atlantic/Stanley",
  397. Calendar.SEPTEMBER, 1, Calendar.SUNDAY, 2000 * 3600,
  398. Calendar.APRIL, 3, Calendar.SUNDAY, 2000 * 3600);
  399. timezones0.put("Atlantic/Stanley", tz);
  400. tz = new SimpleTimeZone
  401. (-3500 * 3600, "CNT",
  402. Calendar.MARCH, 2, Calendar.SUNDAY, 60000,
  403. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 60000);
  404. timezones0.put("CNT", tz);
  405. timezones0.put("America/St_Johns", tz);
  406. tz = new SimpleTimeZone
  407. (-3000 * 3600, "America/Godthab",
  408. Calendar.MARCH, 30, -Calendar.SATURDAY, 22000 * 3600,
  409. Calendar.OCTOBER, 30, -Calendar.SATURDAY, 23000 * 3600);
  410. timezones0.put("America/Godthab", tz);
  411. tz = new SimpleTimeZone
  412. (-3000 * 3600, "America/Miquelon",
  413. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600,
  414. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 2000 * 3600);
  415. timezones0.put("America/Miquelon", tz);
  416. tz = new SimpleTimeZone
  417. (-3000 * 3600, "America/Montevideo",
  418. Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600,
  419. Calendar.MARCH, 2, Calendar.SUNDAY, 2000 * 3600);
  420. timezones0.put("America/Montevideo", tz);
  421. tz = new SimpleTimeZone
  422. (-3000 * 3600, "America/Sao_Paulo",
  423. Calendar.NOVEMBER, 1, Calendar.SUNDAY, 0 * 3600,
  424. Calendar.FEBRUARY, -1, Calendar.SUNDAY, 0 * 3600);
  425. timezones0.put("America/Sao_Paulo", tz);
  426. tz = new SimpleTimeZone(-3000 * 3600, "AGT");
  427. timezones0.put("AGT", tz);
  428. timezones0.put("America/Araguaina", tz);
  429. timezones0.put("America/Argentina/Buenos_Aires", tz);
  430. timezones0.put("America/Argentina/Catamarca", tz);
  431. timezones0.put("America/Argentina/Cordoba", tz);
  432. timezones0.put("America/Argentina/Jujuy", tz);
  433. timezones0.put("America/Argentina/La_Rioja", tz);
  434. timezones0.put("America/Argentina/Mendoza", tz);
  435. timezones0.put("America/Argentina/Rio_Gallegos", tz);
  436. timezones0.put("America/Argentina/San_Juan", tz);
  437. timezones0.put("America/Argentina/Tucuman", tz);
  438. timezones0.put("America/Argentina/Ushuaia", tz);
  439. timezones0.put("America/Bahia", tz);
  440. timezones0.put("America/Belem", tz);
  441. timezones0.put("America/Cayenne", tz);
  442. timezones0.put("America/Fortaleza", tz);
  443. timezones0.put("America/Maceio", tz);
  444. timezones0.put("America/Paramaribo", tz);
  445. timezones0.put("America/Recife", tz);
  446. timezones0.put("Antarctica/Rothera", tz);
  447. tz = new SimpleTimeZone(-2000 * 3600, "America/Noronha");
  448. timezones0.put("America/Noronha", tz);
  449. timezones0.put("Atlantic/South_Georgia", tz);
  450. tz = new SimpleTimeZone
  451. (-1000 * 3600, "America/Scoresbysund",
  452. Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600,
  453. Calendar.OCTOBER, -1, Calendar.SUNDAY, 1000 * 3600);
  454. timezones0.put("America/Scoresbysund", tz);
  455. timezones0.put("Atlantic/Azores", tz);
  456. tz = new SimpleTimeZone(-1000 * 3600, "Atlantic/Cape_Verde");
  457. timezones0.put("Atlantic/Cape_Verde", tz);
  458. tz = new SimpleTimeZone(0 * 3600, "GMT");
  459. timezones0.put("GMT", tz);
  460. timezones0.put("UTC", tz);
  461. timezones0.put("Africa/Abidjan", tz);
  462. timezones0.put("Africa/Accra", tz);
  463. timezones0.put("Africa/Bamako", tz);
  464. timezones0.put("Africa/Banjul", tz);
  465. timezones0.put("Africa/Bissau", tz);
  466. timezones0.put("Africa/Casablanca", tz);
  467. timezones0.put("Africa/Conakry", tz);
  468. timezones0.put("Africa/Dakar", tz);
  469. timezones0.put("Africa/El_Aaiun", tz);
  470. timezones0.put("Africa/Freetown", tz);
  471. timezones0.put("Africa/Lome", tz);
  472. timezones0.put("Africa/Monrovia", tz);
  473. timezones0.put("Africa/Nouakchott", tz);
  474. timezones0.put("Africa/Ouagadougou", tz);
  475. timezones0.put("Africa/Sao_Tome", tz);
  476. timezones0.put("America/Danmarkshavn", tz);
  477. timezones0.put("Atlantic/Reykjavik", tz);
  478. timezones0.put("Atlantic/St_Helena", tz);
  479. tz = new SimpleTimeZone
  480. (0 * 3600, "WET",
  481. Calendar.MARCH, -1, Calendar.SUNDAY, 1000 * 3600,
  482. Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600);
  483. timezones0.put("WET", tz);
  484. timezones0.put("Atlantic/Canary", tz);
  485. timezones0.put("Atlantic/Faroe", tz);
  486. timezones0.put("Atlantic/Madeira", tz);
  487. timezones0.put("Europe/Dublin", tz);
  488. timezones0.put("Europe/Guernsey", tz);
  489. timezones0.put("Europe/Isle_of_Man", tz);
  490. timezones0.put("Europe/Jersey", tz);
  491. timezones0.put("Europe/Lisbon", tz);
  492. timezones0.put("Europe/London", tz);
  493. tz = new SimpleTimeZone(1000 * 3600, "Africa/Algiers");
  494. timezones0.put("Africa/Algiers", tz);
  495. timezones0.put("Africa/Bangui", tz);
  496. timezones0.put("Africa/Brazzaville", tz);
  497. timezones0.put("Africa/Douala", tz);
  498. timezones0.put("Africa/Kinshasa", tz);
  499. timezones0.put("Africa/Lagos", tz);
  500. timezones0.put("Africa/Libreville", tz);
  501. timezones0.put("Africa/Luanda", tz);
  502. timezones0.put("Africa/Malabo", tz);
  503. timezones0.put("Africa/Ndjamena", tz);
  504. timezones0.put("Africa/Niamey", tz);
  505. timezones0.put("Africa/Porto-Novo", tz);
  506. tz = new SimpleTimeZone
  507. (1000 * 3600, "Africa/Windhoek",
  508. Calendar.SEPTEMBER, 1, Calendar.SUNDAY, 2000 * 3600,
  509. Calendar.APRIL, 1, Calendar.SUNDAY, 2000 * 3600);
  510. timezones0.put("Africa/Windhoek", tz);
  511. tz = new SimpleTimeZone
  512. (1000 * 3600, "CET",
  513. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  514. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  515. timezones0.put("CET", tz);
  516. timezones0.put("ECT", tz);
  517. timezones0.put("MET", tz);
  518. timezones0.put("Africa/Ceuta", tz);
  519. timezones0.put("Africa/Tunis", tz);
  520. timezones0.put("Arctic/Longyearbyen", tz);
  521. timezones0.put("Atlantic/Jan_Mayen", tz);
  522. timezones0.put("Europe/Amsterdam", tz);
  523. timezones0.put("Europe/Andorra", tz);
  524. timezones0.put("Europe/Belgrade", tz);
  525. timezones0.put("Europe/Berlin", tz);
  526. timezones0.put("Europe/Bratislava", tz);
  527. timezones0.put("Europe/Brussels", tz);
  528. timezones0.put("Europe/Budapest", tz);
  529. timezones0.put("Europe/Copenhagen", tz);
  530. timezones0.put("Europe/Gibraltar", tz);
  531. timezones0.put("Europe/Ljubljana", tz);
  532. timezones0.put("Europe/Luxembourg", tz);
  533. timezones0.put("Europe/Madrid", tz);
  534. timezones0.put("Europe/Malta", tz);
  535. timezones0.put("Europe/Monaco", tz);
  536. timezones0.put("Europe/Oslo", tz);
  537. timezones0.put("Europe/Paris", tz);
  538. timezones0.put("Europe/Podgorica", tz);
  539. timezones0.put("Europe/Prague", tz);
  540. timezones0.put("Europe/Rome", tz);
  541. timezones0.put("Europe/San_Marino", tz);
  542. timezones0.put("Europe/Sarajevo", tz);
  543. timezones0.put("Europe/Skopje", tz);
  544. timezones0.put("Europe/Stockholm", tz);
  545. timezones0.put("Europe/Tirane", tz);
  546. timezones0.put("Europe/Vaduz", tz);
  547. timezones0.put("Europe/Vatican", tz);
  548. timezones0.put("Europe/Vienna", tz);
  549. timezones0.put("Europe/Warsaw", tz);
  550. timezones0.put("Europe/Zagreb", tz);
  551. timezones0.put("Europe/Zurich", tz);
  552. tz = new SimpleTimeZone
  553. (2000 * 3600, "ART",
  554. Calendar.APRIL, -1, Calendar.FRIDAY, 0 * 3600,
  555. Calendar.SEPTEMBER, -1, Calendar.THURSDAY, 24000 * 3600);
  556. timezones0.put("ART", tz);
  557. timezones0.put("Africa/Cairo", tz);
  558. tz = new SimpleTimeZone(2000 * 3600, "CAT");
  559. timezones0.put("CAT", tz);
  560. timezones0.put("Africa/Blantyre", tz);
  561. timezones0.put("Africa/Bujumbura", tz);
  562. timezones0.put("Africa/Gaborone", tz);
  563. timezones0.put("Africa/Harare", tz);
  564. timezones0.put("Africa/Johannesburg", tz);
  565. timezones0.put("Africa/Kigali", tz);
  566. timezones0.put("Africa/Lubumbashi", tz);
  567. timezones0.put("Africa/Lusaka", tz);
  568. timezones0.put("Africa/Maputo", tz);
  569. timezones0.put("Africa/Maseru", tz);
  570. timezones0.put("Africa/Mbabane", tz);
  571. timezones0.put("Africa/Tripoli", tz);
  572. timezones0.put("Asia/Jerusalem", tz);
  573. tz = new SimpleTimeZone
  574. (2000 * 3600, "Asia/Amman",
  575. Calendar.MARCH, -1, Calendar.THURSDAY, 0 * 3600,
  576. Calendar.OCTOBER, -1, Calendar.FRIDAY, 1000 * 3600);
  577. timezones0.put("Asia/Amman", tz);
  578. tz = new SimpleTimeZone
  579. (2000 * 3600, "Asia/Beirut",
  580. Calendar.MARCH, -1, Calendar.SUNDAY, 0 * 3600,
  581. Calendar.OCTOBER, -1, Calendar.SUNDAY, 0 * 3600);
  582. timezones0.put("Asia/Beirut", tz);
  583. tz = new SimpleTimeZone
  584. (2000 * 3600, "Asia/Damascus",
  585. Calendar.APRIL, 1, 0, 0 * 3600,
  586. Calendar.OCTOBER, 1, 0, 0 * 3600);
  587. timezones0.put("Asia/Damascus", tz);
  588. tz = new SimpleTimeZone
  589. (2000 * 3600, "Asia/Gaza",
  590. Calendar.APRIL, 1, 0, 0 * 3600,
  591. Calendar.OCTOBER, 3, Calendar.FRIDAY, 0 * 3600);
  592. timezones0.put("Asia/Gaza", tz);
  593. tz = new SimpleTimeZone
  594. (2000 * 3600, "EET",
  595. Calendar.MARCH, -1, Calendar.SUNDAY, 3000 * 3600,
  596. Calendar.OCTOBER, -1, Calendar.SUNDAY, 4000 * 3600);
  597. timezones0.put("EET", tz);
  598. timezones0.put("Asia/Istanbul", tz);
  599. timezones0.put("Asia/Nicosia", tz);
  600. timezones0.put("Europe/Athens", tz);
  601. timezones0.put("Europe/Bucharest", tz);
  602. timezones0.put("Europe/Chisinau", tz);
  603. timezones0.put("Europe/Helsinki", tz);
  604. timezones0.put("Europe/Istanbul", tz);
  605. timezones0.put("Europe/Kiev", tz);
  606. timezones0.put("Europe/Mariehamn", tz);
  607. timezones0.put("Europe/Nicosia", tz);
  608. timezones0.put("Europe/Riga", tz);
  609. timezones0.put("Europe/Simferopol", tz);
  610. timezones0.put("Europe/Sofia", tz);
  611. timezones0.put("Europe/Tallinn", tz);
  612. timezones0.put("Europe/Uzhgorod", tz);
  613. timezones0.put("Europe/Vilnius", tz);
  614. timezones0.put("Europe/Zaporozhye", tz);
  615. tz = new SimpleTimeZone
  616. (2000 * 3600, "Europe/Kaliningrad",
  617. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  618. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  619. timezones0.put("Europe/Kaliningrad", tz);
  620. timezones0.put("Europe/Minsk", tz);
  621. tz = new SimpleTimeZone
  622. (3000 * 3600, "Asia/Baghdad",
  623. Calendar.APRIL, 1, 0, 3000 * 3600,
  624. Calendar.OCTOBER, 1, 0, 4000 * 3600);
  625. timezones0.put("Asia/Baghdad", tz);
  626. tz = new SimpleTimeZone
  627. (3000 * 3600, "Europe/Moscow",
  628. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  629. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  630. timezones0.put("Europe/Moscow", tz);
  631. timezones0.put("Europe/Volgograd", tz);
  632. tz = new SimpleTimeZone(3000 * 3600, "EAT");
  633. timezones0.put("EAT", tz);
  634. timezones0.put("Africa/Addis_Ababa", tz);
  635. timezones0.put("Africa/Asmara", tz);
  636. timezones0.put("Africa/Dar_es_Salaam", tz);
  637. timezones0.put("Africa/Djibouti", tz);
  638. timezones0.put("Africa/Kampala", tz);
  639. timezones0.put("Africa/Khartoum", tz);
  640. timezones0.put("Africa/Mogadishu", tz);
  641. timezones0.put("Africa/Nairobi", tz);
  642. timezones0.put("Antarctica/Syowa", tz);
  643. timezones0.put("Asia/Aden", tz);
  644. timezones0.put("Asia/Bahrain", tz);
  645. timezones0.put("Asia/Kuwait", tz);
  646. timezones0.put("Asia/Qatar", tz);
  647. timezones0.put("Asia/Riyadh", tz);
  648. timezones0.put("Indian/Antananarivo", tz);
  649. timezones0.put("Indian/Comoro", tz);
  650. timezones0.put("Indian/Mayotte", tz);
  651. tz = new SimpleTimeZone(3500 * 3600, "Asia/Tehran");
  652. timezones0.put("Asia/Tehran", tz);
  653. tz = new SimpleTimeZone
  654. (4000 * 3600, "Asia/Baku",
  655. Calendar.MARCH, -1, Calendar.SUNDAY, 4000 * 3600,
  656. Calendar.OCTOBER, -1, Calendar.SUNDAY, 5000 * 3600);
  657. timezones0.put("Asia/Baku", tz);
  658. tz = new SimpleTimeZone
  659. (4000 * 3600, "Asia/Yerevan",
  660. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  661. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  662. timezones0.put("Asia/Yerevan", tz);
  663. timezones0.put("Europe/Samara", tz);
  664. tz = new SimpleTimeZone(4000 * 3600, "NET");
  665. timezones0.put("NET", tz);
  666. timezones0.put("Asia/Dubai", tz);
  667. timezones0.put("Asia/Muscat", tz);
  668. timezones0.put("Asia/Tbilisi", tz);
  669. timezones0.put("Indian/Mahe", tz);
  670. timezones0.put("Indian/Mauritius", tz);
  671. timezones0.put("Indian/Reunion", tz);
  672. tz = new SimpleTimeZone(4500 * 3600, "Asia/Kabul");
  673. timezones0.put("Asia/Kabul", tz);
  674. tz = new SimpleTimeZone
  675. (5000 * 3600, "Asia/Yekaterinburg",
  676. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  677. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  678. timezones0.put("Asia/Yekaterinburg", tz);
  679. tz = new SimpleTimeZone(5000 * 3600, "PLT");
  680. timezones0.put("PLT", tz);
  681. timezones0.put("Asia/Aqtau", tz);
  682. timezones0.put("Asia/Aqtobe", tz);
  683. timezones0.put("Asia/Ashgabat", tz);
  684. timezones0.put("Asia/Dushanbe", tz);
  685. timezones0.put("Asia/Karachi", tz);
  686. timezones0.put("Asia/Oral", tz);
  687. timezones0.put("Asia/Samarkand", tz);
  688. timezones0.put("Asia/Tashkent", tz);
  689. timezones0.put("Indian/Kerguelen", tz);
  690. timezones0.put("Indian/Maldives", tz);
  691. tz = new SimpleTimeZone(5500 * 3600, "BST");
  692. timezones0.put("BST", tz);
  693. timezones0.put("IST", tz);
  694. timezones0.put("Asia/Calcutta", tz);
  695. timezones0.put("Asia/Colombo", tz);
  696. tz = new SimpleTimeZone(5750 * 3600, "Asia/Katmandu");
  697. timezones0.put("Asia/Katmandu", tz);
  698. tz = new SimpleTimeZone(6000 * 3600, "Antarctica/Mawson");
  699. timezones0.put("Antarctica/Mawson", tz);
  700. timezones0.put("Antarctica/Vostok", tz);
  701. timezones0.put("Asia/Almaty", tz);
  702. timezones0.put("Asia/Bishkek", tz);
  703. timezones0.put("Asia/Dhaka", tz);
  704. timezones0.put("Asia/Qyzylorda", tz);
  705. timezones0.put("Asia/Thimphu", tz);
  706. timezones0.put("Indian/Chagos", tz);
  707. tz = new SimpleTimeZone
  708. (6000 * 3600, "Asia/Novosibirsk",
  709. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  710. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  711. timezones0.put("Asia/Novosibirsk", tz);
  712. timezones0.put("Asia/Omsk", tz);
  713. tz = new SimpleTimeZone(6500 * 3600, "Asia/Rangoon");
  714. timezones0.put("Asia/Rangoon", tz);
  715. timezones0.put("Indian/Cocos", tz);
  716. tz = new SimpleTimeZone(7000 * 3600, "VST");
  717. timezones0.put("VST", tz);
  718. timezones0.put("Antarctica/Davis", tz);
  719. timezones0.put("Asia/Bangkok", tz);
  720. timezones0.put("Asia/Jakarta", tz);
  721. timezones0.put("Asia/Phnom_Penh", tz);
  722. timezones0.put("Asia/Pontianak", tz);
  723. timezones0.put("Asia/Saigon", tz);
  724. timezones0.put("Asia/Vientiane", tz);
  725. timezones0.put("Indian/Christmas", tz);
  726. tz = new SimpleTimeZone
  727. (7000 * 3600, "Asia/Hovd",
  728. Calendar.MARCH, -1, Calendar.SATURDAY, 2000 * 3600,
  729. Calendar.SEPTEMBER, -1, Calendar.SATURDAY, 2000 * 3600);
  730. timezones0.put("Asia/Hovd", tz);
  731. tz = new SimpleTimeZone
  732. (7000 * 3600, "Asia/Krasnoyarsk",
  733. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  734. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  735. timezones0.put("Asia/Krasnoyarsk", tz);
  736. tz = new SimpleTimeZone(8000 * 3600, "CTT");
  737. timezones0.put("CTT", tz);
  738. timezones0.put("Antarctica/Casey", tz);
  739. timezones0.put("Asia/Brunei", tz);
  740. timezones0.put("Asia/Chongqing", tz);
  741. timezones0.put("Asia/Harbin", tz);
  742. timezones0.put("Asia/Hong_Kong", tz);
  743. timezones0.put("Asia/Kashgar", tz);
  744. timezones0.put("Asia/Kuala_Lumpur", tz);
  745. timezones0.put("Asia/Kuching", tz);
  746. timezones0.put("Asia/Macau", tz);
  747. timezones0.put("Asia/Makassar", tz);
  748. timezones0.put("Asia/Manila", tz);
  749. timezones0.put("Asia/Shanghai", tz);
  750. timezones0.put("Asia/Singapore", tz);
  751. timezones0.put("Asia/Taipei", tz);
  752. timezones0.put("Asia/Urumqi", tz);
  753. timezones0.put("Australia/Perth", tz);
  754. tz = new SimpleTimeZone
  755. (8000 * 3600, "Asia/Irkutsk",
  756. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  757. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  758. timezones0.put("Asia/Irkutsk", tz);
  759. tz = new SimpleTimeZone
  760. (8000 * 3600, "Asia/Ulaanbaatar",
  761. Calendar.MARCH, -1, Calendar.SATURDAY, 2000 * 3600,
  762. Calendar.SEPTEMBER, -1, Calendar.SATURDAY, 2000 * 3600);
  763. timezones0.put("Asia/Ulaanbaatar", tz);
  764. tz = new SimpleTimeZone(8750 * 3600, "Australia/Eucla");
  765. timezones0.put("Australia/Eucla", tz);
  766. tz = new SimpleTimeZone
  767. (9000 * 3600, "Asia/Choibalsan",
  768. Calendar.MARCH, -1, Calendar.SATURDAY, 2000 * 3600,
  769. Calendar.SEPTEMBER, -1, Calendar.SATURDAY, 2000 * 3600);
  770. timezones0.put("Asia/Choibalsan", tz);
  771. tz = new SimpleTimeZone(9000 * 3600, "JST");
  772. timezones0.put("JST", tz);
  773. timezones0.put("Asia/Dili", tz);
  774. timezones0.put("Asia/Jayapura", tz);
  775. timezones0.put("Asia/Pyongyang", tz);
  776. timezones0.put("Asia/Seoul", tz);
  777. timezones0.put("Asia/Tokyo", tz);
  778. timezones0.put("Pacific/Palau", tz);
  779. tz = new SimpleTimeZone
  780. (9000 * 3600, "Asia/Yakutsk",
  781. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  782. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  783. timezones0.put("Asia/Yakutsk", tz);
  784. tz = new SimpleTimeZone
  785. (9500 * 3600, "Australia/Adelaide",
  786. Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600,
  787. Calendar.MARCH, -1, Calendar.SUNDAY, 3000 * 3600);
  788. timezones0.put("Australia/Adelaide", tz);
  789. timezones0.put("Australia/Broken_Hill", tz);
  790. tz = new SimpleTimeZone(9500 * 3600, "ACT");
  791. timezones0.put("ACT", tz);
  792. timezones0.put("Australia/Darwin", tz);
  793. tz = new SimpleTimeZone(10000 * 3600, "Antarctica/DumontDUrville");
  794. timezones0.put("Antarctica/DumontDUrville", tz);
  795. timezones0.put("Australia/Brisbane", tz);
  796. timezones0.put("Australia/Lindeman", tz);
  797. timezones0.put("Pacific/Guam", tz);
  798. timezones0.put("Pacific/Port_Moresby", tz);
  799. timezones0.put("Pacific/Saipan", tz);
  800. timezones0.put("Pacific/Truk", tz);
  801. tz = new SimpleTimeZone
  802. (10000 * 3600, "Asia/Sakhalin",
  803. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  804. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  805. timezones0.put("Asia/Sakhalin", tz);
  806. timezones0.put("Asia/Vladivostok", tz);
  807. tz = new SimpleTimeZone
  808. (10000 * 3600, "Australia/Currie",
  809. Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600,
  810. Calendar.MARCH, -1, Calendar.SUNDAY, 3000 * 3600);
  811. timezones0.put("Australia/Currie", tz);
  812. timezones0.put("Australia/Hobart", tz);
  813. tz = new SimpleTimeZone
  814. (10000 * 3600, "AET",
  815. Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600,
  816. Calendar.MARCH, -1, Calendar.SUNDAY, 3000 * 3600);
  817. timezones0.put("AET", tz);
  818. timezones0.put("Australia/Melbourne", tz);
  819. timezones0.put("Australia/Sydney", tz);
  820. tz = new SimpleTimeZone
  821. (10500 * 3600, "Australia/Lord_Howe",
  822. Calendar.OCTOBER, -1, Calendar.SUNDAY, 2000 * 3600,
  823. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600, 500 * 3600);
  824. timezones0.put("Australia/Lord_Howe", tz);
  825. tz = new SimpleTimeZone
  826. (11000 * 3600, "Asia/Magadan",
  827. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  828. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  829. timezones0.put("Asia/Magadan", tz);
  830. tz = new SimpleTimeZone(11000 * 3600, "SST");
  831. timezones0.put("SST", tz);
  832. timezones0.put("Pacific/Efate", tz);
  833. timezones0.put("Pacific/Guadalcanal", tz);
  834. timezones0.put("Pacific/Kosrae", tz);
  835. timezones0.put("Pacific/Noumea", tz);
  836. timezones0.put("Pacific/Ponape", tz);
  837. tz = new SimpleTimeZone(11500 * 3600, "Pacific/Norfolk");
  838. timezones0.put("Pacific/Norfolk", tz);
  839. tz = new SimpleTimeZone
  840. (12000 * 3600, "NST",
  841. Calendar.OCTOBER, 1, Calendar.SUNDAY, 2000 * 3600,
  842. Calendar.MARCH, 3, Calendar.SUNDAY, 3000 * 3600);
  843. timezones0.put("NST", tz);
  844. timezones0.put("Antarctica/McMurdo", tz);
  845. timezones0.put("Antarctica/South_Pole", tz);
  846. timezones0.put("Pacific/Auckland", tz);
  847. tz = new SimpleTimeZone
  848. (12000 * 3600, "Asia/Anadyr",
  849. Calendar.MARCH, -1, Calendar.SUNDAY, 2000 * 3600,
  850. Calendar.OCTOBER, -1, Calendar.SUNDAY, 3000 * 3600);
  851. timezones0.put("Asia/Anadyr", tz);
  852. timezones0.put("Asia/Kamchatka", tz);
  853. tz = new SimpleTimeZone(12000 * 3600, "Pacific/Fiji");
  854. timezones0.put("Pacific/Fiji", tz);
  855. timezones0.put("Pacific/Funafuti", tz);
  856. timezones0.put("Pacific/Kwajalein", tz);
  857. timezones0.put("Pacific/Majuro", tz);
  858. timezones0.put("Pacific/Nauru", tz);
  859. timezones0.put("Pacific/Tarawa", tz);
  860. timezones0.put("Pacific/Wake", tz);
  861. timezones0.put("Pacific/Wallis", tz);
  862. tz = new SimpleTimeZone
  863. (12750 * 3600, "Pacific/Chatham",
  864. Calendar.OCTOBER, 1, Calendar.SUNDAY, 2750 * 3600,
  865. Calendar.MARCH, 3, Calendar.SUNDAY, 3750 * 3600);
  866. timezones0.put("Pacific/Chatham", tz);
  867. tz = new SimpleTimeZone(13000 * 3600, "Pacific/Enderbury");
  868. timezones0.put("Pacific/Enderbury", tz);
  869. timezones0.put("Pacific/Tongatapu", tz);
  870. tz = new SimpleTimeZone(14000 * 3600, "Pacific/Kiritimati");
  871. timezones0.put("Pacific/Kiritimati", tz);
  872. }
  873. return timezones0;
  874. }
  875. /**
  876. * Maps a time zone name (with optional GMT offset and daylight time
  877. * zone name) to one of the known time zones. This method called
  878. * with the result of <code>System.getProperty("user.timezone")</code>
  879. * or <code>getDefaultTimeZoneId()</code>. Note that giving one of
  880. * the standard tz data names from ftp://elsie.nci.nih.gov/pub/ is
  881. * preferred.
  882. * The time zone name can be given as follows:
  883. * <code>(standard zone name)[(GMT offset)[(DST zone name)[DST offset]]]
  884. * </code>
  885. * <p>
  886. * If only a (standard zone name) is given (no numbers in the
  887. * String) then it gets mapped directly to the TimeZone with that
  888. * name, if that fails null is returned.
  889. * <p>
  890. * Alternately, a POSIX-style TZ string can be given, defining the time zone:
  891. * <code>std offset dst offset,date/time,date/time</code>
  892. * See the glibc manual, or the man page for <code>tzset</code> for details
  893. * of this format.
  894. * <p>
  895. * A GMT offset is the offset to add to the local time to get GMT.
  896. * If a (GMT offset) is included (either in seconds or hours) then
  897. * an attempt is made to find a TimeZone name matching both the name
  898. * and the offset (that doesn't observe daylight time, if the
  899. * timezone observes daylight time then you must include a daylight
  900. * time zone name after the offset), if that fails then a TimeZone
  901. * with the given GMT offset is returned (whether or not the
  902. * TimeZone observes daylight time is ignored), if that also fails
  903. * the GMT TimeZone is returned.
  904. * <p>
  905. * If the String ends with (GMT offset)(daylight time zone name)
  906. * then an attempt is made to find a TimeZone with the given name and
  907. * GMT offset that also observes (the daylight time zone name is not
  908. * currently used in any other way), if that fails a TimeZone with
  909. * the given GMT offset that observes daylight time is returned, if
  910. * that also fails the GMT TimeZone is returned.
  911. * <p>
  912. * Examples: In Chicago, the time zone id could be "CST6CDT", but
  913. * the preferred name would be "America/Chicago". In Indianapolis
  914. * (which does not have Daylight Savings Time) the string could be
  915. * "EST5", but the preferred name would be "America/Indianapolis".
  916. * The standard time zone name for The Netherlands is "Europe/Amsterdam",
  917. * but can also be given as "CET-1CEST".
  918. */
  919. static TimeZone getDefaultTimeZone(String sysTimeZoneId)
  920. {
  921. String stdName = null;
  922. int stdOffs;
  923. int dstOffs;
  924. try
  925. {
  926. int idLength = sysTimeZoneId.length();
  927. int index = 0;
  928. int prevIndex;
  929. char c;
  930. // get std
  931. do
  932. c = sysTimeZoneId.charAt(index);
  933. while (c != '+' && c != '-' && c != ',' && c != ':'
  934. && ! Character.isDigit(c) && c != '\0' && ++index < idLength);
  935. if (index >= idLength)
  936. return getTimeZoneInternal(sysTimeZoneId);
  937. stdName = sysTimeZoneId.substring(0, index);
  938. prevIndex = index;
  939. // get the std offset
  940. do
  941. c = sysTimeZoneId.charAt(index++);
  942. while ((c == '-' || c == '+' || c == ':' || Character.isDigit(c))
  943. && index < idLength);
  944. if (index < idLength)
  945. index--;
  946. { // convert the dst string to a millis number
  947. String offset = sysTimeZoneId.substring(prevIndex, index);
  948. prevIndex = index;
  949. if (offset.charAt(0) == '+' || offset.charAt(0) == '-')
  950. stdOffs = parseTime(offset.substring(1));
  951. else
  952. stdOffs = parseTime(offset);
  953. if (offset.charAt(0) == '-')
  954. stdOffs = -stdOffs;
  955. // TZ timezone offsets are positive when WEST of the meridian.
  956. stdOffs = -stdOffs;
  957. }
  958. // Done yet? (Format: std offset)
  959. if (index >= idLength)
  960. {
  961. // Do we have an existing timezone with that name and offset?
  962. TimeZone tz = getTimeZoneInternal(stdName);
  963. if (tz != null)
  964. if (tz.getRawOffset() == stdOffs)
  965. return tz;
  966. // Custom then.
  967. return new SimpleTimeZone(stdOffs, stdName);
  968. }
  969. // get dst
  970. do
  971. c = sysTimeZoneId.charAt(index);
  972. while (c != '+' && c != '-' && c != ',' && c != ':'
  973. && ! Character.isDigit(c) && c != '\0' && ++index < idLength);
  974. // Done yet? (Format: std offset dst)
  975. if (index >= idLength)
  976. {
  977. // Do we have an existing timezone with that name and offset
  978. // which has DST?
  979. TimeZone tz = getTimeZoneInternal(stdName);
  980. if (tz != null)
  981. if (tz.getRawOffset() == stdOffs && tz.useDaylightTime())
  982. return tz;
  983. // Custom then.
  984. return new SimpleTimeZone(stdOffs, stdName);
  985. }
  986. // get the dst offset
  987. prevIndex = index;
  988. do
  989. c = sysTimeZoneId.charAt(index++);
  990. while ((c == '-' || c == '+' || c == ':' || Character.isDigit(c))
  991. && index < idLength);
  992. if (index < idLength)
  993. index--;
  994. if (index == prevIndex && (c == ',' || c == ';'))
  995. {
  996. // Missing dst offset defaults to one hour ahead of standard
  997. // time.
  998. dstOffs = stdOffs + 60 * 60 * 1000;
  999. }
  1000. else
  1001. { // convert the dst string to a millis number
  1002. String offset = sysTimeZoneId.substring(prevIndex, index);
  1003. prevIndex = index;
  1004. if (offset.charAt(0) == '+' || offset.charAt(0) == '-')
  1005. dstOffs = parseTime(offset.substring(1));
  1006. else
  1007. dstOffs = parseTime(offset);
  1008. if (offset.charAt(0) == '-')
  1009. dstOffs = -dstOffs;
  1010. // TZ timezone offsets are positive when WEST of the meridian.
  1011. dstOffs = -dstOffs;
  1012. }
  1013. // Done yet? (Format: std offset dst offset)
  1014. // FIXME: We don't support DST without a rule given. Should we?
  1015. if (index >= idLength)
  1016. {
  1017. // Time Zone existing with same name, dst and offsets?
  1018. TimeZone tz = getTimeZoneInternal(stdName);
  1019. if (tz != null)
  1020. if (tz.getRawOffset() == stdOffs && tz.useDaylightTime()
  1021. && tz.getDSTSavings() == (dstOffs - stdOffs))
  1022. return tz;
  1023. return new SimpleTimeZone(stdOffs, stdName);
  1024. }
  1025. // get the DST rule
  1026. if (sysTimeZoneId.charAt(index) == ','
  1027. || sysTimeZoneId.charAt(index) == ';')
  1028. {
  1029. index++;
  1030. int offs = index;
  1031. while (sysTimeZoneId.charAt(index) != ','
  1032. && sysTimeZoneId.charAt(index) != ';')
  1033. index++;
  1034. String startTime = sysTimeZoneId.substring(offs, index);
  1035. index++;
  1036. String endTime = sysTimeZoneId.substring(index);
  1037. index = startTime.indexOf('/');
  1038. int startMillis;
  1039. int endMillis;
  1040. String startDate;
  1041. String endDate;
  1042. if (index != -1)
  1043. {
  1044. startDate = startTime.substring(0, index);
  1045. startMillis = parseTime(startTime.substring(index + 1));
  1046. }
  1047. else
  1048. {
  1049. startDate = startTime;
  1050. // if time isn't given, default to 2:00:00 AM.
  1051. startMillis = 2 * 60 * 60 * 1000;
  1052. }
  1053. index = endTime.indexOf('/');
  1054. if (index != -1)
  1055. {
  1056. endDate = endTime.substring(0, index);
  1057. endMillis = parseTime(endTime.substring(index + 1));
  1058. }
  1059. else
  1060. {
  1061. endDate = endTime;
  1062. // if time isn't given, default to 2:00:00 AM.
  1063. endMillis = 2 * 60 * 60 * 1000;
  1064. }
  1065. int[] start = getDateParams(startDate);
  1066. int[] end = getDateParams(endDate);
  1067. return new SimpleTimeZone(stdOffs, stdName, start[0], start[1],
  1068. start[2], startMillis, end[0], end[1],
  1069. end[2], endMillis, (dstOffs - stdOffs));
  1070. }
  1071. }
  1072. // FIXME: Produce a warning here?
  1073. catch (IndexOutOfBoundsException _)
  1074. {
  1075. }
  1076. catch (NumberFormatException _)
  1077. {
  1078. }
  1079. return null;
  1080. }
  1081. /**
  1082. * Parses and returns the params for a POSIX TZ date field,
  1083. * in the format int[]{ month, day, dayOfWeek }, following the
  1084. * SimpleTimeZone constructor rules.
  1085. */
  1086. private static int[] getDateParams(String date)
  1087. {
  1088. int[] dayCount = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
  1089. int month;
  1090. if (date.charAt(0) == 'M' || date.charAt(0) == 'm')
  1091. {
  1092. int day;
  1093. // Month, week of month, day of week
  1094. // "Mm.w.d". d is between 0 (Sunday) and 6. Week w is
  1095. // between 1 and 5; Week 1 is the first week in which day d
  1096. // occurs and Week 5 specifies the last d day in the month.
  1097. // Month m is between 1 and 12.
  1098. month = Integer.parseInt(date.substring(1, date.indexOf('.')));
  1099. int week = Integer.parseInt(date.substring(date.indexOf('.') + 1,
  1100. date.lastIndexOf('.')));
  1101. int dayOfWeek = Integer.parseInt(date.substring(date.lastIndexOf('.')
  1102. + 1));
  1103. dayOfWeek++; // Java day of week is one-based, Sunday is first day.
  1104. if (week == 5)
  1105. day = -1; // last day of month is -1 in java, 5 in TZ
  1106. else
  1107. {
  1108. // First day of week starting on or after. For example,
  1109. // to specify the second Sunday of April, set month to
  1110. // APRIL, day-of-month to 8, and day-of-week to -SUNDAY.
  1111. day = (week - 1) * 7 + 1;
  1112. dayOfWeek = -dayOfWeek;
  1113. }
  1114. month--; // Java month is zero-based.
  1115. return new int[] { month, day, dayOfWeek };
  1116. }
  1117. // julian day, either zero-based 0<=n<=365 (incl feb 29)
  1118. // or one-based 1<=n<=365 (no feb 29)
  1119. int julianDay; // Julian day,
  1120. if (date.charAt(0) != 'J' || date.charAt(0) != 'j')
  1121. {
  1122. julianDay = Integer.parseInt(date.substring(1));
  1123. julianDay++; // make 1-based
  1124. // Adjust day count to include feb 29.
  1125. dayCount = new int[]
  1126. {
  1127. 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335
  1128. };
  1129. }
  1130. else
  1131. // 1-based julian day
  1132. julianDay = Integer.parseInt(date);
  1133. int i = 11;
  1134. while (i > 0)
  1135. if (dayCount[i] < julianDay)
  1136. break;
  1137. else
  1138. i--;
  1139. julianDay -= dayCount[i];
  1140. month = i;
  1141. return new int[] { month, julianDay, 0 };
  1142. }
  1143. /**
  1144. * Parses a time field hh[:mm[:ss]], returning the result
  1145. * in milliseconds. No leading sign.
  1146. */
  1147. private static int parseTime(String time)
  1148. {
  1149. int millis = 0;
  1150. int i = 0;
  1151. while (i < time.length())
  1152. if (time.charAt(i) == ':')
  1153. break;
  1154. else
  1155. i++;
  1156. millis = 60 * 60 * 1000 * Integer.parseInt(time.substring(0, i));
  1157. if (i >= time.length())
  1158. return millis;
  1159. int iprev = ++i;
  1160. while (i < time.length())
  1161. if (time.charAt(i) == ':')
  1162. break;
  1163. else
  1164. i++;
  1165. millis += 60 * 1000 * Integer.parseInt(time.substring(iprev, i));
  1166. if (i >= time.length())
  1167. return millis;
  1168. millis += 1000 * Integer.parseInt(time.substring(++i));
  1169. return millis;
  1170. }
  1171. /**
  1172. * Gets the time zone offset, for current date, modified in case of
  1173. * daylight savings. This is the offset to add to UTC to get the local
  1174. * time.
  1175. * @param era the era of the given date
  1176. * @param year the year of the given date
  1177. * @param month the month of the given date, 0 for January.
  1178. * @param day the day of month
  1179. * @param dayOfWeek the day of week
  1180. * @param milliseconds the millis in the day (in local standard time)
  1181. * @return the time zone offset in milliseconds.
  1182. */
  1183. public abstract int getOffset(int era, int year, int month,
  1184. int day, int dayOfWeek, int milliseconds);
  1185. /**
  1186. * Get the time zone offset for the specified date, modified in case of
  1187. * daylight savings. This is the offset to add to UTC to get the local
  1188. * time.
  1189. * @param date the date represented in millisecends
  1190. * since January 1, 1970 00:00:00 GMT.
  1191. * @since 1.4
  1192. */
  1193. public int getOffset(long date)
  1194. {
  1195. return (inDaylightTime(new Date(date))
  1196. ? getRawOffset() + getDSTSavings()
  1197. : getRawOffset());
  1198. }
  1199. /**
  1200. * Gets the time zone offset, ignoring daylight savings. This is
  1201. * the offset to add to UTC to get the local time.
  1202. * @return the time zone offset in milliseconds.
  1203. */
  1204. public abstract int getRawOffset();
  1205. /**
  1206. * Sets the time zone offset, ignoring daylight savings. This is
  1207. * the offset to add to UTC to get the local time.
  1208. * @param offsetMillis the time zone offset to GMT.
  1209. */
  1210. public abstract void setRawOffset(int offsetMillis);
  1211. /**
  1212. * Gets the identifier of this time zone. For instance, PST for
  1213. * Pacific Standard Time.
  1214. * @returns the ID of this time zone.
  1215. */
  1216. public String getID()
  1217. {
  1218. return ID;
  1219. }
  1220. /**
  1221. * Sets the identifier of this time zone. For instance, PST for
  1222. * Pacific Standard Time.
  1223. * @param id the new time zone ID.
  1224. * @throws NullPointerException if <code>id</code> is <code>null</code>
  1225. */
  1226. public void setID(String id)
  1227. {
  1228. if (id == null)
  1229. throw new NullPointerException();
  1230. this.ID = id;
  1231. }
  1232. /**
  1233. * This method returns a string name of the time zone suitable
  1234. * for displaying to the user. The string returned will be the long
  1235. * description of the timezone in the current locale. The name
  1236. * displayed will assume daylight savings time is not in effect.
  1237. *
  1238. * @return The name of the time zone.
  1239. */
  1240. public final String getDisplayName()
  1241. {
  1242. return (getDisplayName(false, LONG, Locale.getDefault()));
  1243. }
  1244. /**
  1245. * This method returns a string name of the time zone suitable
  1246. * for displaying to the user. The string returned will be the long
  1247. * description of the timezone in the specified locale. The name
  1248. * displayed will assume daylight savings time is not in effect.
  1249. *
  1250. * @param locale The locale for this timezone name.
  1251. *
  1252. * @return The name of the time zone.
  1253. */
  1254. public final String getDisplayName(Locale locale)
  1255. {
  1256. return (getDisplayName(false, LONG, locale));
  1257. }
  1258. /**
  1259. * This method returns a string name of the time zone suitable
  1260. * for displaying to the user. The string returned will be of the
  1261. * specified type in the current locale.
  1262. *
  1263. * @param dst Whether or not daylight savings time is in effect.
  1264. * @param style <code>LONG</code> for a long name, <code>SHORT</code> for
  1265. * a short abbreviation.
  1266. *
  1267. * @return The name of the time zone.
  1268. */
  1269. public final String getDisplayName(boolean dst, int style)
  1270. {
  1271. return (getDisplayName(dst, style, Locale.getDefault()));
  1272. }
  1273. /**
  1274. * This method returns a string name of the time zone suitable
  1275. * for displaying to the user. The string returned will be of the
  1276. * specified type in the specified locale.
  1277. *
  1278. * @param dst Whether or not daylight savings time is in effect.
  1279. * @param style <code>LONG</code> for a long name, <code>SHORT</code> for
  1280. * a short abbreviation.
  1281. * @param locale The locale for this timezone name.
  1282. *
  1283. * @return The name of the time zone.
  1284. */
  1285. public String getDisplayName(boolean dst, int style, Locale locale)
  1286. {
  1287. DateFormatSymbols dfs;
  1288. try
  1289. {
  1290. dfs = new DateFormatSymbols(locale);
  1291. // The format of the value returned is defined by us.
  1292. String[][]zoneinfo = dfs.getZoneStrings();
  1293. for (int i = 0; i < zoneinfo.length; i++)
  1294. {
  1295. if (zoneinfo[i][0].equals(getID()))
  1296. {
  1297. if (!dst)
  1298. {
  1299. if (style == SHORT)
  1300. return (zoneinfo[i][2]);
  1301. else
  1302. return (zoneinfo[i][1]);
  1303. }
  1304. else
  1305. {
  1306. if (style == SHORT)
  1307. return (zoneinfo[i][4]);
  1308. else
  1309. return (zoneinfo[i][3]);
  1310. }
  1311. }
  1312. }
  1313. }
  1314. catch (MissingResourceException e)
  1315. {
  1316. }
  1317. return getDefaultDisplayName(dst);
  1318. }
  1319. private String getDefaultDisplayName(boolean dst)
  1320. {
  1321. int offset = getRawOffset() + (dst ? getDSTSavings() : 0);
  1322. CPStringBuilder sb = new CPStringBuilder(9);
  1323. sb.append("GMT");
  1324. offset = offset / (1000 * 60);
  1325. int hours = Math.abs(offset) / 60;
  1326. int minutes = Math.abs(offset) % 60;
  1327. if (minutes != 0 || hours != 0)
  1328. {
  1329. sb.append(offset >= 0 ? '+' : '-');
  1330. sb.append((char) ('0' + hours / 10));
  1331. sb.append((char) ('0' + hours % 10));
  1332. sb.append(':');
  1333. sb.append((char) ('0' + minutes / 10));
  1334. sb.append((char) ('0' + minutes % 10));
  1335. }
  1336. return sb.toString();
  1337. }
  1338. /**
  1339. * Returns true, if this time zone uses Daylight Savings Time.
  1340. */
  1341. public abstract boolean useDaylightTime();
  1342. /**
  1343. * Returns true, if the given date is in Daylight Savings Time in this
  1344. * time zone.
  1345. * @param date the given Date.
  1346. */
  1347. public abstract boolean inDaylightTime(Date date);
  1348. /**
  1349. * Gets the daylight savings offset. This is a positive offset in
  1350. * milliseconds with respect to standard time. Typically this
  1351. * is one hour, but for some time zones this may be half an our.
  1352. * <p>The default implementation returns 3600000 milliseconds
  1353. * (one hour) if the time zone uses daylight savings time
  1354. * (as specified by {@link #useDaylightTime()}), otherwise
  1355. * it returns 0.
  1356. * @return the daylight savings offset in milliseconds.
  1357. * @since 1.4
  1358. */
  1359. public int getDSTSavings ()
  1360. {
  1361. return useDaylightTime () ? 3600000 : 0;
  1362. }
  1363. /**
  1364. * Gets the TimeZone for the given ID.
  1365. * @param ID the time zone identifier.
  1366. * @return The time zone for the identifier or GMT, if no such time
  1367. * zone exists.
  1368. */
  1369. private static TimeZone getTimeZoneInternal(String ID)
  1370. {
  1371. // First check timezones hash
  1372. TimeZone tz = null;
  1373. TimeZone tznew = null;
  1374. for (int pass = 0; pass < 2; pass++)
  1375. {
  1376. synchronized (TimeZone.class)
  1377. {
  1378. tz = timezones().get(ID);
  1379. if (tz != null)
  1380. {
  1381. if (!tz.getID().equals(ID))
  1382. {
  1383. // We always return a timezone with the requested ID.
  1384. // This is the same behaviour as with JDK1.2.
  1385. tz = (TimeZone) tz.clone();
  1386. tz.setID(ID);
  1387. // We also save the alias, so that we return the same
  1388. // object again if getTimeZone is called with the same
  1389. // alias.
  1390. timezones().put(ID, tz);
  1391. }
  1392. return tz;
  1393. }
  1394. else if (tznew != null)
  1395. {
  1396. timezones().put(ID, tznew);
  1397. return tznew;
  1398. }
  1399. }
  1400. if (pass == 1 || zoneinfo_dir == null)
  1401. return null;
  1402. // aliases0 is never changing after first timezones(), so should
  1403. // be safe without synchronization.
  1404. String zonename = aliases0.get(ID);
  1405. if (zonename == null)
  1406. zonename = ID;
  1407. // Read the file outside of the critical section, it is expensive.
  1408. tznew = ZoneInfo.readTZFile (ID, zoneinfo_dir
  1409. + File.separatorChar + zonename);
  1410. if (tznew == null)
  1411. return null;
  1412. }
  1413. return null;
  1414. }
  1415. /**
  1416. * Gets the TimeZone for the given ID.
  1417. * @param ID the time zone identifier.
  1418. * @return The time zone for the identifier or GMT, if no such time
  1419. * zone exists.
  1420. */
  1421. public static TimeZone getTimeZone(String ID)
  1422. {
  1423. // Check for custom IDs first
  1424. if (ID.startsWith("GMT") && ID.length() > 3)
  1425. {
  1426. int pos = 3;
  1427. int offset_direction = 1;
  1428. if (ID.charAt(pos) == '-')
  1429. {
  1430. offset_direction = -1;
  1431. pos++;
  1432. }
  1433. else if (ID.charAt(pos) == '+')
  1434. {
  1435. pos++;
  1436. }
  1437. try
  1438. {
  1439. int hour, minute;
  1440. String offset_str = ID.substring(pos);
  1441. int idx = offset_str.indexOf(":");
  1442. if (idx != -1)
  1443. {
  1444. hour = Integer.parseInt(offset_str.substring(0, idx));
  1445. minute = Integer.parseInt(offset_str.substring(idx + 1));
  1446. }
  1447. else
  1448. {
  1449. int offset_length = offset_str.length();
  1450. if (offset_length <= 2)
  1451. {
  1452. // Only hour
  1453. hour = Integer.parseInt(offset_str);
  1454. minute = 0;
  1455. }
  1456. else
  1457. {
  1458. // hour and minute, not separated by colon
  1459. hour = Integer.parseInt
  1460. (offset_str.substring(0, offset_length - 2));
  1461. minute = Integer.parseInt
  1462. (offset_str.substring(offset_length - 2));
  1463. }
  1464. }
  1465. // Custom IDs have to be normalized
  1466. CPStringBuilder sb = new CPStringBuilder(9);
  1467. sb.append("GMT");
  1468. sb.append(offset_direction >= 0 ? '+' : '-');
  1469. sb.append((char) ('0' + hour / 10));
  1470. sb.append((char) ('0' + hour % 10));
  1471. sb.append(':');
  1472. sb.append((char) ('0' + minute / 10));
  1473. sb.append((char) ('0' + minute % 10));
  1474. ID = sb.toString();
  1475. return new SimpleTimeZone((hour * (60 * 60 * 1000)
  1476. + minute * (60 * 1000))
  1477. * offset_direction, ID);
  1478. }
  1479. catch (NumberFormatException e)
  1480. {
  1481. }
  1482. }
  1483. TimeZone tz = getTimeZoneInternal(ID);
  1484. if (tz != null)
  1485. return tz;
  1486. return new SimpleTimeZone(0, "GMT");
  1487. }
  1488. /**
  1489. * Gets the available IDs according to the given time zone
  1490. * offset.
  1491. * @param rawOffset the given time zone GMT offset.
  1492. * @return An array of IDs, where the time zone has the specified GMT
  1493. * offset. For example <code>{"Phoenix", "Denver"}</code>, since both have
  1494. * GMT-07:00, but differ in daylight savings behaviour.
  1495. */
  1496. public static String[] getAvailableIDs(int rawOffset)
  1497. {
  1498. synchronized (TimeZone.class)
  1499. {
  1500. HashMap<String,TimeZone> h = timezones();
  1501. int count = 0;
  1502. if (zoneinfo_dir == null)
  1503. {
  1504. Iterator<Map.Entry<String,TimeZone>> iter = h.entrySet().iterator();
  1505. while (iter.hasNext())
  1506. {
  1507. // Don't iterate the values, since we want to count
  1508. // doubled values (aliases)
  1509. Map.Entry<String,TimeZone> entry = iter.next();
  1510. if (entry.getValue().getRawOffset() == rawOffset)
  1511. count++;
  1512. }
  1513. String[] ids = new String[count];
  1514. count = 0;
  1515. iter = h.entrySet().iterator();
  1516. while (iter.hasNext())
  1517. {
  1518. Map.Entry<String,TimeZone> entry = iter.next();
  1519. if (entry.getValue().getRawOffset() == rawOffset)
  1520. ids[count++] = (String) entry.getKey();
  1521. }
  1522. return ids;
  1523. }
  1524. }
  1525. String[] s = getAvailableIDs();
  1526. int count = 0;
  1527. for (int i = 0; i < s.length; i++)
  1528. {
  1529. TimeZone t = getTimeZoneInternal(s[i]);
  1530. if (t == null || t.getRawOffset() != rawOffset)
  1531. s[i] = null;
  1532. else
  1533. count++;
  1534. }
  1535. String[] ids = new String[count];
  1536. count = 0;
  1537. for (int i = 0; i < s.length; i++)
  1538. if (s[i] != null)
  1539. ids[count++] = s[i];
  1540. return ids;
  1541. }
  1542. private static int getAvailableIDs(File d, String prefix, ArrayList<String[]> list)
  1543. {
  1544. String[] files = d.list();
  1545. int count = files.length;
  1546. boolean top = prefix.length() == 0;
  1547. list.add (files);
  1548. for (int i = 0; i < files.length; i++)
  1549. {
  1550. if (top
  1551. && (files[i].equals("posix")
  1552. || files[i].equals("right")
  1553. || files[i].endsWith(".tab")
  1554. || aliases0.get(files[i]) != null))
  1555. {
  1556. files[i] = null;
  1557. count--;
  1558. continue;
  1559. }
  1560. File f = new File(d, files[i]);
  1561. if (f.isDirectory())
  1562. {
  1563. count += getAvailableIDs(f, prefix + files[i]
  1564. + File.separatorChar, list) - 1;
  1565. files[i] = null;
  1566. }
  1567. else
  1568. files[i] = prefix + files[i];
  1569. }
  1570. return count;
  1571. }
  1572. /**
  1573. * Gets all available IDs.
  1574. * @return An array of all supported IDs.
  1575. */
  1576. public static String[] getAvailableIDs()
  1577. {
  1578. synchronized (TimeZone.class)
  1579. {
  1580. HashMap<String,TimeZone> h = timezones();
  1581. if (zoneinfo_dir == null)
  1582. return h.keySet().toArray(new String[h.size()]);
  1583. if (availableIDs != null)
  1584. {
  1585. String[] ids = new String[availableIDs.length];
  1586. for (int i = 0; i < availableIDs.length; i++)
  1587. ids[i] = availableIDs[i];
  1588. return ids;
  1589. }
  1590. File d = new File(zoneinfo_dir);
  1591. ArrayList<String[]> list = new ArrayList<String[]>(30);
  1592. int count = getAvailableIDs(d, "", list) + aliases0.size();
  1593. availableIDs = new String[count];
  1594. String[] ids = new String[count];
  1595. count = 0;
  1596. for (int i = 0; i < list.size(); i++)
  1597. {
  1598. String[] s = list.get(i);
  1599. for (int j = 0; j < s.length; j++)
  1600. if (s[j] != null)
  1601. {
  1602. availableIDs[count] = s[j];
  1603. ids[count++] = s[j];
  1604. }
  1605. }
  1606. Iterator<Map.Entry<String,String>> iter = aliases0.entrySet().iterator();
  1607. while (iter.hasNext())
  1608. {
  1609. Map.Entry<String,String> entry = iter.next();
  1610. availableIDs[count] = entry.getKey();
  1611. ids[count++] = entry.getKey();
  1612. }
  1613. return ids;
  1614. }
  1615. }
  1616. /**
  1617. * Returns the time zone under which the host is running. This
  1618. * can be changed with setDefault.
  1619. *
  1620. * @return A clone of the current default time zone for this host.
  1621. * @see #setDefault
  1622. */
  1623. public static TimeZone getDefault()
  1624. {
  1625. return (TimeZone) defaultZone().clone();
  1626. }
  1627. public static void setDefault(TimeZone zone)
  1628. {
  1629. // Hmmmm. No Security checks?
  1630. defaultZone0 = zone;
  1631. }
  1632. /**
  1633. * Test if the other time zone uses the same rule and only
  1634. * possibly differs in ID. This implementation for this particular
  1635. * class will return true if the raw offsets are identical. Subclasses
  1636. * should override this method if they use daylight savings.
  1637. * @return true if this zone has the same raw offset
  1638. */
  1639. public boolean hasSameRules(TimeZone other)
  1640. {
  1641. return other.getRawOffset() == getRawOffset();
  1642. }
  1643. /**
  1644. * Returns a clone of this object. I can't imagine, why this is
  1645. * useful for a time zone.
  1646. */
  1647. public Object clone()
  1648. {
  1649. try
  1650. {
  1651. return super.clone();
  1652. }
  1653. catch (CloneNotSupportedException ex)
  1654. {
  1655. return null;
  1656. }
  1657. }
  1658. }