29 *
30 * The original version of this source code and documentation is copyrighted
31 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
32 * materials are provided under terms of a License Agreement between Taligent
33 * and Sun. This technology is protected by multiple US and International
34 * patents. This notice and attribution to Taligent may not be removed.
35 * Taligent is a registered trademark of Taligent, Inc.
36 *
37 */
38
39 package java.util;
40
41 import java.io.Serializable;
42 import java.lang.ref.SoftReference;
43 import java.security.AccessController;
44 import java.security.PrivilegedAction;
45 import java.util.concurrent.ConcurrentHashMap;
46 import sun.misc.SharedSecrets;
47 import sun.misc.JavaAWTAccess;
48 import sun.security.action.GetPropertyAction;
49 import sun.util.TimeZoneNameUtility;
50 import sun.util.calendar.ZoneInfo;
51 import sun.util.calendar.ZoneInfoFile;
52
53 /**
54 * <code>TimeZone</code> represents a time zone offset, and also figures out daylight
55 * savings.
56 *
57 * <p>
58 * Typically, you get a <code>TimeZone</code> using <code>getDefault</code>
59 * which creates a <code>TimeZone</code> based on the time zone where the program
60 * is running. For example, for a program running in Japan, <code>getDefault</code>
61 * creates a <code>TimeZone</code> object based on Japanese Standard Time.
62 *
63 * <p>
64 * You can also get a <code>TimeZone</code> using <code>getTimeZone</code>
65 * along with a time zone ID. For instance, the time zone ID for the
66 * U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a
67 * U.S. Pacific Time <code>TimeZone</code> object with:
68 * <blockquote><pre>
69 * TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
386 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
387 *
388 * @param daylight {@code true} specifying a Daylight Saving Time name, or
389 * {@code false} specifying a Standard Time name
390 * @param style either {@link #LONG} or {@link #SHORT}
391 * @param locale the locale in which to supply the display name.
392 * @return the human-readable name of this time zone in the given locale.
393 * @exception IllegalArgumentException if {@code style} is invalid.
394 * @exception NullPointerException if {@code locale} is {@code null}.
395 * @since 1.2
396 * @see java.text.DateFormatSymbols#getZoneStrings()
397 */
398 public String getDisplayName(boolean daylight, int style, Locale locale) {
399 if (style != SHORT && style != LONG) {
400 throw new IllegalArgumentException("Illegal style: " + style);
401 }
402
403 String id = getID();
404 String[] names = getDisplayNames(id, locale);
405 if (names == null) {
406 if (id.startsWith("GMT")) {
407 char sign = id.charAt(3);
408 if (sign == '+' || sign == '-') {
409 return id;
410 }
411 }
412 int offset = getRawOffset();
413 if (daylight) {
414 offset += getDSTSavings();
415 }
416 return ZoneInfoFile.toCustomID(offset);
417 }
418
419 int index = daylight ? 3 : 1;
420 if (style == SHORT) {
421 index++;
422 }
423 return names[index];
424 }
425
426 private static class DisplayNames {
|
29 *
30 * The original version of this source code and documentation is copyrighted
31 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
32 * materials are provided under terms of a License Agreement between Taligent
33 * and Sun. This technology is protected by multiple US and International
34 * patents. This notice and attribution to Taligent may not be removed.
35 * Taligent is a registered trademark of Taligent, Inc.
36 *
37 */
38
39 package java.util;
40
41 import java.io.Serializable;
42 import java.lang.ref.SoftReference;
43 import java.security.AccessController;
44 import java.security.PrivilegedAction;
45 import java.util.concurrent.ConcurrentHashMap;
46 import sun.misc.SharedSecrets;
47 import sun.misc.JavaAWTAccess;
48 import sun.security.action.GetPropertyAction;
49 import sun.util.locale.provider.TimeZoneNameUtility;
50 import sun.util.calendar.ZoneInfo;
51 import sun.util.calendar.ZoneInfoFile;
52
53 /**
54 * <code>TimeZone</code> represents a time zone offset, and also figures out daylight
55 * savings.
56 *
57 * <p>
58 * Typically, you get a <code>TimeZone</code> using <code>getDefault</code>
59 * which creates a <code>TimeZone</code> based on the time zone where the program
60 * is running. For example, for a program running in Japan, <code>getDefault</code>
61 * creates a <code>TimeZone</code> object based on Japanese Standard Time.
62 *
63 * <p>
64 * You can also get a <code>TimeZone</code> using <code>getTimeZone</code>
65 * along with a time zone ID. For instance, the time zone ID for the
66 * U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a
67 * U.S. Pacific Time <code>TimeZone</code> object with:
68 * <blockquote><pre>
69 * TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
386 * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
387 *
388 * @param daylight {@code true} specifying a Daylight Saving Time name, or
389 * {@code false} specifying a Standard Time name
390 * @param style either {@link #LONG} or {@link #SHORT}
391 * @param locale the locale in which to supply the display name.
392 * @return the human-readable name of this time zone in the given locale.
393 * @exception IllegalArgumentException if {@code style} is invalid.
394 * @exception NullPointerException if {@code locale} is {@code null}.
395 * @since 1.2
396 * @see java.text.DateFormatSymbols#getZoneStrings()
397 */
398 public String getDisplayName(boolean daylight, int style, Locale locale) {
399 if (style != SHORT && style != LONG) {
400 throw new IllegalArgumentException("Illegal style: " + style);
401 }
402
403 String id = getID();
404 String[] names = getDisplayNames(id, locale);
405 if (names == null) {
406 if (id.startsWith("GMT") && id.length() > 3) {
407 char sign = id.charAt(3);
408 if (sign == '+' || sign == '-') {
409 return id;
410 }
411 }
412 int offset = getRawOffset();
413 if (daylight) {
414 offset += getDSTSavings();
415 }
416 return ZoneInfoFile.toCustomID(offset);
417 }
418
419 int index = daylight ? 3 : 1;
420 if (style == SHORT) {
421 index++;
422 }
423 return names[index];
424 }
425
426 private static class DisplayNames {
|