1 // 2016 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html#License 3 /* 4 * @(#)TimeZone.java 1.51 00/01/19 5 * 6 * Copyright (C) 1996-2016, International Business Machines 7 * Corporation and others. All Rights Reserved. 8 */ 9 10 package com.ibm.icu.util; 11 12 import java.io.Serializable; 13 import java.util.Date; 14 import java.util.GregorianCalendar; 15 import java.util.Locale; 16 import java.util.SimpleTimeZone; 17 18 import com.ibm.icu.util.ULocale.Category; 19 20 /** 21 * {@icuenhanced java.util.TimeZone}.{@icu _usage_} 22 * 23 * <p><code>TimeZone</code> represents a time zone offset, and also computes daylight 24 * savings. 25 * 26 * <p>Typically, you get a <code>TimeZone</code> using {@link #getDefault()} 27 * which creates a <code>TimeZone</code> based on the time zone where the program 28 * is running. For example, for a program running in Japan, <code>getDefault</code> 29 * creates a <code>TimeZone</code> object based on Japanese Standard Time. 30 * 31 * <p>You can also get a <code>TimeZone</code> using {@link #getTimeZone(String)} 32 * along with a time zone ID. For instance, the time zone ID for the 33 * U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a 34 * U.S. Pacific Time <code>TimeZone</code> object with: 35 * 36 * <blockquote> 37 * <pre> 38 * TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); 39 * </pre> 40 * </blockquote> 41 * You can use the {@link #getAvailableIDs()} method to iterate through 42 * all the supported time zone IDs. You can then choose a 43 * supported ID to get a <code>TimeZone</code>. 44 * If the time zone you want is not represented by one of the 45 * supported IDs, then you can create a custom time zone ID with 46 * the following syntax: 47 * 48 * <blockquote> 49 * <pre> 50 * GMT[+|-]hh[[:]mm] 51 * </pre> 52 * </blockquote> 53 * 54 * For example, you might specify GMT+14:00 as a custom 55 * time zone ID. The <code>TimeZone</code> that is returned 56 * when you specify a custom time zone ID does not include 57 * daylight savings time. 58 * 59 * <p>For compatibility with JDK 1.1.x, some other three-letter time zone IDs 60 * (such as "PST", "CTT", "AST") are also supported. However, <strong>their 61 * use is deprecated</strong> because the same abbreviation is often used 62 * for multiple time zones (for example, "CST" could be U.S. "Central Standard 63 * Time" and "China Standard Time"), and the Java platform can then only 64 * recognize one of them. 65 * 66 * <p><strong>Note:</strong> Starting from ICU4J 4.0, you can optionally choose 67 * JDK <code>TimeZone</code> as the time zone implementation. The TimeZone factory 68 * method <code>getTimeZone</code> creates an instance of ICU's own <code>TimeZone</code> 69 * subclass by default. If you want to use the JDK implementation always, you can 70 * set the default time zone implementation type by the new method 71 * <code>setDefaultTimeZoneType</code>. Alternatively, you can change the initial 72 * default implementation type by setting a property below. 73 * 74 * <blockquote> 75 * <pre> 76 * # 77 * # The default TimeZone implementation type used by the ICU TimeZone 78 * # factory method. [ ICU | JDK ] 79 * # 80 * com.ibm.icu.util.TimeZone.DefaultTimeZoneType = ICU 81 * </pre> 82 * </blockquote> 83 * 84 * <p>This property is included in ICUConfig.properties in com.ibm.icu package. When the 85 * <code>TimeZone</code> class is loaded, the initialization code checks if the property 86 * <code>com.ibm.icu.util.TimeZone.DefaultTimeZoneType=xxx</code> is defined by the system 87 * properties. If not available, then it loads ICUConfig.properties to get the default 88 * time zone implementation type. The property setting is only used for the initial 89 * default value and you can change the default type by calling 90 * <code>setDefaultTimeZoneType</code> at runtime. 91 * 92 * @see Calendar 93 * @see GregorianCalendar 94 * @see SimpleTimeZone 95 * @author Mark Davis, Deborah Goldsmith, Chen-Lieh Huang, Alan Liu 96 * @stable ICU 2.0 97 */ 98 public class TimeZone implements Serializable, Cloneable, Freezable<TimeZone> { 99 private static final long serialVersionUID = 1L; 100 101 /** 102 * @internal 103 */ 104 public final java.util.TimeZone timeZone; 105 106 /** 107 * @internal 108 * @param delegate the TimeZone to which to delegate 109 */ 110 public TimeZone(java.util.TimeZone delegate) { 111 this.timeZone = delegate; 112 } 113 114 // /** 115 // * {@icu} A logger for TimeZone. Will be null if logging is not on by way of system 116 // * property: "icu4j.debug.logging" 117 // * @draft ICU 4.4 118 // * @provisional This API might change or be removed in a future release. 119 // */ 120 // public static ICULogger TimeZoneLogger = ICULogger.getICULogger(TimeZone.class.getName()); 121 122 /** 123 * Default constructor. (For invocation by subclass constructors, 124 * typically implicit.) 125 * @stable ICU 2.8 126 */ 127 public TimeZone() { 128 this.timeZone = java.util.TimeZone.getDefault(); 129 } 130 131 /** 132 * {@icu} A time zone implementation type indicating ICU's own TimeZone used by 133 * <code>getTimeZone</code>, <code>setDefaultTimeZoneType</code> 134 * and <code>getDefaultTimeZoneType</code>. 135 * @stable ICU 4.0 136 */ 137 public static final int TIMEZONE_ICU = 0; 138 /** 139 * {@icu} A time zone implementation type indicating JDK TimeZone used by 140 * <code>getTimeZone</code>, <code>setDefaultTimeZoneType</code> 141 * and <code>getDefaultTimeZoneType</code>. 142 * @stable ICU 4.0 143 */ 144 public static final int TIMEZONE_JDK = 1; 145 146 /** 147 * A style specifier for <code>getDisplayName()</code> indicating 148 * a short name, such as "PST." 149 * @see #LONG 150 * @stable ICU 2.0 151 */ 152 public static final int SHORT = 0; 153 154 /** 155 * A style specifier for <code>getDisplayName()</code> indicating 156 * a long name, such as "Pacific Standard Time." 157 * @see #SHORT 158 * @stable ICU 2.0 159 */ 160 public static final int LONG = 1; 161 162 // /** 163 // * {@icu} A style specifier for <code>getDisplayName()</code> indicating 164 // * a short generic name, such as "PT." 165 // * @see #LONG_GENERIC 166 // * @draft ICU 4.4 167 // * @provisional This API might change or be removed in a future release. 168 // */ 169 // public static final int SHORT_GENERIC = 2; 170 // 171 // /** 172 // * {@icu} A style specifier for <code>getDisplayName()</code> indicating 173 // * a long generic name, such as "Pacific Time." 174 // * @see #SHORT_GENERIC 175 // * @draft ICU 4.4 176 // * @provisional This API might change or be removed in a future release. 177 // */ 178 // public static final int LONG_GENERIC = 3; 179 // 180 // /** 181 // * {@icu} A style specifier for <code>getDisplayName()</code> indicating 182 // * a short name derived from the timezone's offset, such as "-0800." 183 // * @see #LONG_GMT 184 // * @draft ICU 4.4 185 // * @provisional This API might change or be removed in a future release. 186 // */ 187 // public static final int SHORT_GMT = 4; 188 // 189 // /** 190 // * {@icu} A style specifier for <code>getDisplayName()</code> indicating 191 // * a long name derived from the timezone's offset, such as "GMT-08:00." 192 // * @see #SHORT_GMT 193 // * @draft ICU 4.4 194 // * @provisional This API might change or be removed in a future release. 195 // */ 196 // public static final int LONG_GMT = 5; 197 // 198 // /** 199 // * {@icu} A style specifier for <code>getDisplayName()</code> indicating 200 // * a short name derived from the timezone's short standard or daylight 201 // * timezone name ignoring commonlyUsed, such as "PDT." 202 // * @draft ICU 4.4 203 // * @provisional This API might change or be removed in a future release. 204 // */ 205 // 206 // public static final int SHORT_COMMONLY_USED = 6; 207 // 208 // /** 209 // * {@icu} A style specifier for <code>getDisplayName()</code> indicating 210 // * a long name derived from the timezone's fallback name, such as 211 // * "United States (Los Angeles)." 212 // * @draft ICU 4.4 213 // * @provisional This API might change or be removed in a future release. 214 // */ 215 // public static final int GENERIC_LOCATION = 7; 216 // 217 // /** 218 // * Gets the time zone offset, for current date, modified in case of 219 // * daylight savings. This is the offset to add *to* UTC to get local time. 220 // * @param era the era of the given date. 221 // * @param year the year in the given date. 222 // * @param month the month in the given date. 223 // * Month is 0-based. e.g., 0 for January. 224 // * @param day the day-in-month of the given date. 225 // * @param dayOfWeek the day-of-week of the given date. 226 // * @param milliseconds the millis in day in <em>standard</em> local time. 227 // * @return the offset to add *to* GMT to get local time. 228 // * @stable ICU 2.0 229 // */ 230 231 // /** 232 // * {@icu} System time zone type constants used by filtering zones in 233 // * {@link TimeZone#getAvailableIDs(SystemTimeZoneType, String, Integer)} 234 // * 235 // * @draft ICU 4.8 236 // * @provisional This API might change or be removed in a future release. 237 // */ 238 // public enum SystemTimeZoneType { 239 // /** 240 // * Any system zones. 241 // * @draft ICU 4.8 242 // * @provisional This API might change or be removed in a future release. 243 // */ 244 // ANY, 245 // 246 // /** 247 // * Canonical system zones. 248 // * @draft ICU 4.8 249 // * @provisional This API might change or be removed in a future release. 250 // */ 251 // CANONICAL, 252 // 253 // /** 254 // * Canonical system zones associated with actual locations. 255 // * @draft ICU 4.8 256 // * @provisional This API might change or be removed in a future release. 257 // */ 258 // CANONICAL_LOCATION, 259 // } 260 261 public int getOffset(int era, int year, int month, int day, 262 int dayOfWeek, int milliseconds) { 263 return timeZone.getOffset(era, year, month, day, dayOfWeek, milliseconds); 264 } 265 266 267 /** 268 * Returns the offset of this time zone from UTC at the specified 269 * date. If Daylight Saving Time is in effect at the specified 270 * date, the offset value is adjusted with the amount of daylight 271 * saving. 272 * 273 * @param date the date represented in milliseconds since January 1, 1970 00:00:00 GMT 274 * @return the amount of time in milliseconds to add to UTC to get local time. 275 * 276 * @see Calendar#ZONE_OFFSET 277 * @see Calendar#DST_OFFSET 278 * @see #getOffset(long, boolean, int[]) 279 * @stable ICU 2.8 280 */ 281 public int getOffset(long date) { 282 return timeZone.getOffset(date); 283 } 284 285 // /** 286 // * Returns the time zone raw and GMT offset for the given moment 287 // * in time. Upon return, local-millis = GMT-millis + rawOffset + 288 // * dstOffset. All computations are performed in the proleptic 289 // * Gregorian calendar. The default implementation in the TimeZone 290 // * class delegates to the 8-argument getOffset(). 291 // * 292 // * @param date moment in time for which to return offsets, in 293 // * units of milliseconds from January 1, 1970 0:00 GMT, either GMT 294 // * time or local wall time, depending on `local'. 295 // * @param local if true, `date' is local wall time; otherwise it 296 // * is in GMT time. 297 // * @param offsets output parameter to receive the raw offset, that 298 // * is, the offset not including DST adjustments, in offsets[0], 299 // * and the DST offset, that is, the offset to be added to 300 // * `rawOffset' to obtain the total offset between local and GMT 301 // * time, in offsets[1]. If DST is not in effect, the DST offset is 302 // * zero; otherwise it is a positive value, typically one hour. 303 // * 304 // * @stable ICU 2.8 305 // */ 306 // public void getOffset(long date, boolean local, int[] offsets) { 307 // throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base"); 308 // } 309 310 /** 311 * Sets the base time zone offset to GMT. 312 * This is the offset to add *to* UTC to get local time. 313 * @param offsetMillis the given base time zone offset to GMT. 314 * @stable ICU 2.0 315 */ 316 public void setRawOffset(int offsetMillis) { 317 if (isFrozen) { 318 throw new UnsupportedOperationException("Attempt to modify a frozen TimeZone instance."); 319 } 320 timeZone.setRawOffset(offsetMillis); 321 } 322 323 /** 324 * Gets unmodified offset, NOT modified in case of daylight savings. 325 * This is the offset to add *to* UTC to get local time. 326 * @return the unmodified offset to add *to* UTC to get local time. 327 * @stable ICU 2.0 328 */ 329 public int getRawOffset() { 330 return timeZone.getRawOffset(); 331 } 332 333 /** 334 * Gets the ID of this time zone. 335 * @return the ID of this time zone. 336 * @stable ICU 2.0 337 */ 338 public String getID() { 339 return timeZone.getID(); 340 } 341 342 /** 343 * Sets the time zone ID. This does not change any other data in 344 * the time zone object. 345 * @param ID the new time zone ID. 346 * @stable ICU 2.0 347 */ 348 public void setID(String ID) { 349 if (isFrozen) { 350 throw new UnsupportedOperationException("Attempt to modify a frozen TimeZone instance."); 351 } 352 timeZone.setID(ID); 353 } 354 355 /** 356 * Returns a name of this time zone suitable for presentation to the user 357 * in the default locale. 358 * This method returns the long generic name. 359 * If the display name is not available for the locale, 360 * a fallback based on the country, city, or time zone id will be used. 361 * @return the human-readable name of this time zone in the default locale. 362 * @stable ICU 2.0 363 */ 364 public final String getDisplayName() { 365 return timeZone.getDisplayName(ULocale.getDefault(Category.DISPLAY).toLocale()); 366 } 367 368 /** 369 * Returns a name of this time zone suitable for presentation to the user 370 * in the specified locale. 371 * This method returns the long generic name. 372 * If the display name is not available for the locale, 373 * a fallback based on the country, city, or time zone id will be used. 374 * @param locale the locale in which to supply the display name. 375 * @return the human-readable name of this time zone in the given locale 376 * or in the default locale if the given locale is not recognized. 377 * @stable ICU 2.0 378 */ 379 public final String getDisplayName(Locale locale) { 380 return timeZone.getDisplayName(locale); 381 } 382 383 /** 384 * Returns a name of this time zone suitable for presentation to the user 385 * in the specified locale. 386 * This method returns the long name, not including daylight savings. 387 * If the display name is not available for the locale, 388 * a fallback based on the country, city, or time zone id will be used. 389 * @param locale the ulocale in which to supply the display name. 390 * @return the human-readable name of this time zone in the given locale 391 * or in the default ulocale if the given ulocale is not recognized. 392 * @stable ICU 3.2 393 */ 394 public final String getDisplayName(ULocale locale) { 395 return timeZone.getDisplayName(locale.toLocale()); 396 } 397 398 /** 399 * Returns a name of this time zone suitable for presentation to the user 400 * in the default locale. 401 * If the display name is not available for the locale, 402 * then this method returns a string in the format 403 * <code>GMT[+-]hh:mm</code>. 404 * @param daylight if true, return the daylight savings name. 405 * @param style the output style of the display name. Valid styles are 406 * <code>SHORT</code>, <code>LONG</code>, <code>SHORT_GENERIC</code>, 407 * <code>LONG_GENERIC</code>, <code>SHORT_GMT</code>, <code>LONG_GMT</code>, 408 * <code>SHORT_COMMONLY_USED</code> or <code>GENERIC_LOCATION</code>. 409 * @return the human-readable name of this time zone in the default locale. 410 * @stable ICU 2.0 411 */ 412 public final String getDisplayName(boolean daylight, int style) { 413 return getDisplayName(daylight, style, ULocale.getDefault(Category.DISPLAY)); 414 } 415 416 /** 417 * Returns a name of this time zone suitable for presentation to the user 418 * in the specified locale. 419 * If the display name is not available for the locale, 420 * then this method returns a string in the format 421 * <code>GMT[+-]hh:mm</code>. 422 * @param daylight if true, return the daylight savings name. 423 * @param style the output style of the display name. Valid styles are 424 * <code>SHORT</code>, <code>LONG</code>, <code>SHORT_GENERIC</code>, 425 * <code>LONG_GENERIC</code>, <code>SHORT_GMT</code>, <code>LONG_GMT</code>, 426 * <code>SHORT_COMMONLY_USED</code> or <code>GENERIC_LOCATION</code>. 427 * @param locale the locale in which to supply the display name. 428 * @return the human-readable name of this time zone in the given locale 429 * or in the default locale if the given locale is not recognized. 430 * @exception IllegalArgumentException style is invalid. 431 * @stable ICU 2.0 432 */ 433 public String getDisplayName(boolean daylight, int style, Locale locale) { 434 return getDisplayName(daylight, style, ULocale.forLocale(locale)); 435 } 436 437 /** 438 * Returns a name of this time zone suitable for presentation to the user 439 * in the specified locale. 440 * If the display name is not available for the locale, 441 * then this method returns a string in the format 442 * <code>GMT[+-]hh:mm</code>. 443 * @param daylight if true, return the daylight savings name. 444 * @param style the output style of the display name. Valid styles are 445 * <code>SHORT</code>, <code>LONG</code>, <code>SHORT_GENERIC</code>, 446 * <code>LONG_GENERIC</code>, <code>SHORT_GMT</code>, <code>LONG_GMT</code>, 447 * <code>SHORT_COMMONLY_USED</code> or <code>GENERIC_LOCATION</code>. 448 * @param locale the locale in which to supply the display name. 449 * @return the human-readable name of this time zone in the given locale 450 * or in the default locale if the given locale is not recognized. 451 * @exception IllegalArgumentException style is invalid. 452 * @stable ICU 3.2 453 */ 454 public String getDisplayName(boolean daylight, int style, ULocale locale) { 455 if (style == SHORT) { 456 return timeZone.getDisplayName(daylight, java.util.TimeZone.SHORT, locale.toLocale()); 457 } else if (style == LONG) { 458 return timeZone.getDisplayName(daylight, java.util.TimeZone.LONG, locale.toLocale()); 459 } else { 460 throw new UnsupportedOperationException("Specified time zone format style is not supported by com.ibm.icu.base"); 461 } 462 } 463 464 /** 465 * Returns the amount of time to be added to local standard time 466 * to get local wall clock time. 467 * <p> 468 * The default implementation always returns 3600000 milliseconds 469 * (i.e., one hour) if this time zone observes Daylight Saving 470 * Time. Otherwise, 0 (zero) is returned. 471 * <p> 472 * If an underlying TimeZone implementation subclass supports 473 * historical Daylight Saving Time changes, this method returns 474 * the known latest daylight saving value. 475 * 476 * @return the amount of saving time in milliseconds 477 * @stable ICU 2.8 478 */ 479 public int getDSTSavings() { 480 return timeZone.getDSTSavings(); 481 } 482 483 /** 484 * Queries if this time zone uses daylight savings time. 485 * @return true if this time zone uses daylight savings time, 486 * false, otherwise. 487 * @stable ICU 2.0 488 */ 489 public boolean useDaylightTime() { 490 return timeZone.useDaylightTime(); 491 } 492 493 // /** 494 // * Queries if this time zone is in daylight saving time or will observe 495 // * daylight saving time at any future time. 496 // * <p>The default implementation in this class returns <code>true</code> if {@link #useDaylightTime()} 497 // * or {@link #inDaylightTime(Date) inDaylightTime(new Date())} returns <code>true</code>. 498 // * <p> 499 // * <strong>Note:</strong> This method was added for JDK compatibility support. 500 // * The JDK's <code>useDaylightTime()</code> only checks the last known rule(s), therefore 501 // * it may return false even the zone observes daylight saving time currently. JDK added 502 // * <code>observesDaylightTime()</code> to resolve the issue. In ICU, {@link #useDaylightTime()} 503 // * works differently. The ICU implementation checks if the zone uses daylight saving time 504 // * in the current calendar year. Therefore, it will never return <code>false</code> if 505 // * daylight saving time is currently used. 506 // * <p> 507 // * ICU's TimeZone subclass implementations override this method to support the same behavior 508 // * with JDK's <code>observesDaylightSavingTime()</code>. Unlike {@link #useDaylightTime()}, 509 // * the implementation does not take past daylight saving time into account, so 510 // * that this method may return <code>false</code> even when {@link #useDaylightTime()} returns 511 // * <code>true</code>. 512 // * 513 // * @return <code>true</code> if this time zone is in daylight saving time or will observe 514 // * daylight saving time at any future time. 515 // * @see #useDaylightTime 516 // * @stable ICU 49 517 // */ 518 // public boolean observesDaylightTime() { 519 // throw new UnsupportedOperationException("Method not supproted by com.ibm.icu.base"); 520 // } 521 522 /** 523 * Queries if the given date is in daylight savings time in 524 * this time zone. 525 * @param date the given Date. 526 * @return true if the given date is in daylight savings time, 527 * false, otherwise. 528 * @stable ICU 2.0 529 */ 530 public boolean inDaylightTime(Date date) { 531 return timeZone.inDaylightTime(date); 532 } 533 534 /** 535 * Gets the <code>TimeZone</code> for the given ID. 536 * 537 * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles", 538 * or a custom ID such as "GMT-8:00". Note that the support of abbreviations, 539 * such as "PST", is for JDK 1.1.x compatibility only and full names should be used. 540 * 541 * @return the specified <code>TimeZone</code>, or the GMT zone if the given ID 542 * cannot be understood. 543 * @stable ICU 2.0 544 */ 545 public static synchronized TimeZone getTimeZone(String ID) { 546 return new TimeZone(java.util.TimeZone.getTimeZone(ID)); 547 } 548 549 /** 550 * Gets the <code>TimeZone</code> for the given ID. The instance of <code>TimeZone</code> 551 * returned by this method is immutable. Any methods mutate the instance({@link #setID(String)}, 552 * {@link #setRawOffset(int)}) will throw <code>UnsupportedOperationException</code> upon its 553 * invocation. 554 * 555 * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles", 556 * or a custom ID such as "GMT-8:00". Note that the support of abbreviations, 557 * such as "PST", is for JDK 1.1.x compatibility only and full names should be used. 558 * 559 * @return the specified <code>TimeZone</code>, or the UNKNOWN_ZONE 560 * if the given ID cannot be understood. 561 * @see #UNKNOWN_ZONE 562 * @draft ICU 49 563 * @provisional This API might change or be removed in a future release. 564 */ 565 public static TimeZone getFrozenTimeZone(String ID) { 566 return getTimeZone(ID).freeze(); 567 } 568 569 /** 570 * Gets the <code>TimeZone</code> for the given ID and the timezone type. 571 * @param ID the ID for a <code>TimeZone</code>, such as "America/Los_Angeles", or a 572 * custom ID such as "GMT-8:00". Note that the support of abbreviations, such as 573 * "PST", is for JDK 1.1.x compatibility only and full names should be used. 574 * @param type Time zone type, either <code>TIMEZONE_ICU</code> or 575 * <code>TIMEZONE_JDK</code>. 576 * @return the specified <code>TimeZone</code>, or the GMT zone if the given ID 577 * cannot be understood. 578 * @stable ICU 4.0 579 */ 580 public static synchronized TimeZone getTimeZone(String ID, int type) { 581 if (type == TIMEZONE_JDK) { 582 return new TimeZone(java.util.TimeZone.getTimeZone(ID)); 583 } 584 throw new UnsupportedOperationException("TIMEZONE_ICU not supported by com.ibm.icu.base"); 585 } 586 587 /** 588 * Sets the default time zone type used by <code>getTimeZone</code>. 589 * @param type time zone type, either <code>TIMEZONE_ICU</code> or 590 * <code>TIMEZONE_JDK</code>. 591 * @stable ICU 4.0 592 */ 593 public static synchronized void setDefaultTimeZoneType(int type) { 594 if (type != TIMEZONE_JDK) { 595 throw new UnsupportedOperationException("TimeZone type other than TIMEZONE_JDK is not supported by com.ibm.icu.base"); 596 } 597 } 598 599 /** 600 * {@icu} Returns the default time zone type currently used. 601 * @return The default time zone type, either <code>TIMEZONE_ICU</code> or 602 * <code>TIMEZONE_JDK</code>. 603 * @stable ICU 4.0 604 */ 605 public static int getDefaultTimeZoneType() { 606 return TIMEZONE_JDK; 607 } 608 609 // /** 610 // * {@icu} Returns a set of time zone ID strings with the given filter conditions. 611 // * <p><b>Note:</b>A <code>Set</code> returned by this method is 612 // * immutable. 613 // * @param zoneType The system time zone type. 614 // * @param region The ISO 3166 two-letter country code or UN M.49 three-digit area code. 615 // * When null, no filtering done by region. 616 // * @param rawOffset An offset from GMT in milliseconds, ignoring the effect of daylight savings 617 // * time, if any. When null, no filtering done by zone offset. 618 // * @return an immutable set of system time zone IDs. 619 // * @see SystemTimeZoneType 620 // * 621 // * @draft ICU 4.8 622 // * @provisional This API might change or be removed in a future release. 623 // */ 624 // public static Set<String> getAvailableIDs(SystemTimeZoneType zoneType, 625 // String region, Integer rawOffset) { 626 // throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base"); 627 // } 628 629 /** 630 * Return a new String array containing all system TimeZone IDs 631 * with the given raw offset from GMT. These IDs may be passed to 632 * <code>get()</code> to construct the corresponding TimeZone 633 * object. 634 * @param rawOffset the offset in milliseconds from GMT 635 * @return an array of IDs for system TimeZones with the given 636 * raw offset. If there are none, return a zero-length array. 637 * @stable ICU 2.0 638 */ 639 public static String[] getAvailableIDs(int rawOffset) { 640 return java.util.TimeZone.getAvailableIDs(rawOffset); 641 642 } 643 644 645 // /** 646 // * Return a new String array containing all system TimeZone IDs 647 // * associated with the given country. These IDs may be passed to 648 // * <code>get()</code> to construct the corresponding TimeZone 649 // * object. 650 // * @param country a two-letter ISO 3166 country code, or <code>null</code> 651 // * to return zones not associated with any country 652 // * @return an array of IDs for system TimeZones in the given 653 // * country. If there are none, return a zero-length array. 654 // * @stable ICU 2.0 655 // */ 656 // public static String[] getAvailableIDs(String country) { 657 // throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base"); 658 // } 659 660 /** 661 * Return a new String array containing all system TimeZone IDs. 662 * These IDs (and only these IDs) may be passed to 663 * <code>get()</code> to construct the corresponding TimeZone 664 * object. 665 * @return an array of all system TimeZone IDs 666 * @stable ICU 2.0 667 */ 668 public static String[] getAvailableIDs() { 669 return java.util.TimeZone.getAvailableIDs(); 670 } 671 672 // /** 673 // * {@icu} Returns the number of IDs in the equivalency group that 674 // * includes the given ID. An equivalency group contains zones 675 // * that have the same GMT offset and rules. 676 // * 677 // * <p>The returned count includes the given ID; it is always >= 1 678 // * for valid IDs. The given ID must be a system time zone. If it 679 // * is not, returns zero. 680 // * @param id a system time zone ID 681 // * @return the number of zones in the equivalency group containing 682 // * 'id', or zero if 'id' is not a valid system ID 683 // * @see #getEquivalentID 684 // * @stable ICU 2.0 685 // */ 686 // public static int countEquivalentIDs(String id) { 687 // throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base"); 688 // } 689 690 // /** 691 // * Returns an ID in the equivalency group that 692 // * includes the given ID. An equivalency group contains zones 693 // * that have the same GMT offset and rules. 694 // * 695 // * <p>The given index must be in the range 0..n-1, where n is the 696 // * value returned by <code>countEquivalentIDs(id)</code>. For 697 // * some value of 'index', the returned value will be equal to the 698 // * given id. If the given id is not a valid system time zone, or 699 // * if 'index' is out of range, then returns an empty string. 700 // * @param id a system time zone ID 701 // * @param index a value from 0 to n-1, where n is the value 702 // * returned by <code>countEquivalentIDs(id)</code> 703 // * @return the ID of the index-th zone in the equivalency group 704 // * containing 'id', or an empty string if 'id' is not a valid 705 // * system ID or 'index' is out of range 706 // * @see #countEquivalentIDs 707 // * @stable ICU 2.0 708 // */ 709 // public static String getEquivalentID(String id, int index) { 710 // throw new UnsupportedOperationException("Method not supported by com.ibm.icu.base"); 711 // } 712 713 /** 714 * Gets the default <code>TimeZone</code> for this host. 715 * The source of the default <code>TimeZone</code> 716 * may vary with implementation. 717 * @return a default <code>TimeZone</code>. 718 * @stable ICU 2.0 719 */ 720 public static TimeZone getDefault() { 721 return new TimeZone(java.util.TimeZone.getDefault()); 722 } 723 724 /** 725 * Sets the <code>TimeZone</code> that is 726 * returned by the <code>getDefault</code> method. If <code>zone</code> 727 * is null, reset the default to the value it had originally when the 728 * VM first started. 729 * @param tz the new default time zone 730 * @stable ICU 2.0 731 */ 732 public static void setDefault(TimeZone tz) { 733 java.util.TimeZone.setDefault(tz.timeZone); 734 } 735 736 /** 737 * Returns true if this zone has the same rule and offset as another zone. 738 * That is, if this zone differs only in ID, if at all. Returns false 739 * if the other zone is null. 740 * @param other the <code>TimeZone</code> object to be compared with 741 * @return true if the other zone is not null and is the same as this one, 742 * with the possible exception of the ID 743 * @stable ICU 2.0 744 */ 745 public boolean hasSameRules(TimeZone other) { 746 return timeZone.hasSameRules(other.timeZone); 747 } 748 749 /** 750 * Overrides clone. 751 * @stable ICU 2.0 752 */ 753 public Object clone() { 754 return new TimeZone((java.util.TimeZone)timeZone.clone()); 755 } 756 757 /** 758 * Overrides equals. 759 * @stable ICU 3.6 760 */ 761 public boolean equals(Object obj){ 762 try { 763 return timeZone.equals(((TimeZone)obj).timeZone); 764 } catch (Exception e) { 765 return false; 766 } 767 } 768 769 /** 770 * Overrides hashCode. 771 * @stable ICU 3.6 772 */ 773 public int hashCode(){ 774 return timeZone.hashCode(); 775 } 776 777 // /** 778 // * {@icu} Returns the time zone data version currently used by ICU. 779 // * 780 // * @return the version string, such as "2007f" 781 // * @throws MissingResourceException if ICU time zone resource bundle 782 // * is missing or the version information is not available. 783 // * 784 // * @stable ICU 3.8 785 // */ 786 // public static synchronized String getTZDataVersion() { 787 // throw new UnsupportedOperationException("Method not supproted by com.ibm.icu.base"); 788 // } 789 790 // /** 791 // * {@icu} Returns the canonical system time zone ID or the normalized 792 // * custom time zone ID for the given time zone ID. 793 // * @param id The input time zone ID to be canonicalized. 794 // * @return The canonical system time zone ID or the custom time zone ID 795 // * in normalized format for the given time zone ID. When the given time zone ID 796 // * is neither a known system time zone ID nor a valid custom time zone ID, 797 // * null is returned. 798 // * @stable ICU 4.0 799 // */ 800 // public static String getCanonicalID(String id) { 801 // throw new UnsupportedOperationException("Method not supproted by com.ibm.icu.base"); 802 // } 803 804 // /** 805 // * {@icu} Returns the canonical system time zone ID or the normalized 806 // * custom time zone ID for the given time zone ID. 807 // * @param id The input time zone ID to be canonicalized. 808 // * @param isSystemID When non-null boolean array is specified and 809 // * the given ID is a known system time zone ID, true is set to <code>isSystemID[0]</code> 810 // * @return The canonical system time zone ID or the custom time zone ID 811 // * in normalized format for the given time zone ID. When the given time zone ID 812 // * is neither a known system time zone ID nor a valid custom time zone ID, 813 // * null is returned. 814 // * @stable ICU 4.0 815 // */ 816 // public static String getCanonicalID(String id, boolean[] isSystemID) { 817 // throw new UnsupportedOperationException("Method not supproted by com.ibm.icu.base"); 818 // } 819 820 // /** 821 // * {@icu} Returns the region code associated with the given 822 // * system time zone ID. The region code is either ISO 3166 823 // * 2-letter country code or UN M.49 3-digit area code. 824 // * When the time zone is not associated with a specific location, 825 // * for example - "Etc/UTC", "EST5EDT", then this method returns 826 // * "001" (UN M.49 area code for World). 827 // * @param id the system time zone ID. 828 // * @return the region code associated with the given 829 // * system time zone ID. 830 // * @throws IllegalArgumentException if <code>id</code> is not a known system ID. 831 // * @see #getAvailableIDs(String) 832 // * 833 // * @draft ICU 4.8 834 // * @provisional This API might change or be removed in a future release. 835 // */ 836 // public static String getRegion(String id) { 837 // throw new UnsupportedOperationException("Method not supproted by com.ibm.icu.base"); 838 // } 839 840 private transient boolean isFrozen = false; 841 842 /** 843 * {@inheritDoc} 844 * @draft ICU 49 845 * @provisional This API might change or be removed in a future release. 846 */ 847 public boolean isFrozen() { 848 return isFrozen; 849 } 850 851 /** 852 * {@inheritDoc} 853 * @draft ICU 49 854 * @provisional This API might change or be removed in a future release. 855 */ 856 public TimeZone freeze() { 857 isFrozen = true; 858 return this; 859 } 860 861 /** 862 * {@inheritDoc} 863 * @draft ICU 49 864 * @provisional This API might change or be removed in a future release. 865 */ 866 public TimeZone cloneAsThawed() { 867 try { 868 TimeZone other = (TimeZone) super.clone(); 869 other.isFrozen = false; 870 return other; 871 } catch (CloneNotSupportedException e) { 872 throw new RuntimeException(e); 873 } 874 } 875 876 } 877 878 //eof 879