rt/emul/compact/src/main/java/java/util/TimeZone.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 04 Oct 2013 12:01:56 +0200
changeset 1340 41046f76a76a
parent 1334 588d5bf7a560
child 1963 4b7ef2a05eb7
permissions -rw-r--r--
Somehow implementing the calendar classes so they compile
     1 /*
     2  * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 
    26 /*
    27  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
    28  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
    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 
    47 /**
    48  * <code>TimeZone</code> represents a time zone offset, and also figures out daylight
    49  * savings.
    50  *
    51  * <p>
    52  * Typically, you get a <code>TimeZone</code> using <code>getDefault</code>
    53  * which creates a <code>TimeZone</code> based on the time zone where the program
    54  * is running. For example, for a program running in Japan, <code>getDefault</code>
    55  * creates a <code>TimeZone</code> object based on Japanese Standard Time.
    56  *
    57  * <p>
    58  * You can also get a <code>TimeZone</code> using <code>getTimeZone</code>
    59  * along with a time zone ID. For instance, the time zone ID for the
    60  * U.S. Pacific Time zone is "America/Los_Angeles". So, you can get a
    61  * U.S. Pacific Time <code>TimeZone</code> object with:
    62  * <blockquote><pre>
    63  * TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
    64  * </pre></blockquote>
    65  * You can use the <code>getAvailableIDs</code> method to iterate through
    66  * all the supported time zone IDs. You can then choose a
    67  * supported ID to get a <code>TimeZone</code>.
    68  * If the time zone you want is not represented by one of the
    69  * supported IDs, then a custom time zone ID can be specified to
    70  * produce a TimeZone. The syntax of a custom time zone ID is:
    71  *
    72  * <blockquote><pre>
    73  * <a name="CustomID"><i>CustomID:</i></a>
    74  *         <code>GMT</code> <i>Sign</i> <i>Hours</i> <code>:</code> <i>Minutes</i>
    75  *         <code>GMT</code> <i>Sign</i> <i>Hours</i> <i>Minutes</i>
    76  *         <code>GMT</code> <i>Sign</i> <i>Hours</i>
    77  * <i>Sign:</i> one of
    78  *         <code>+ -</code>
    79  * <i>Hours:</i>
    80  *         <i>Digit</i>
    81  *         <i>Digit</i> <i>Digit</i>
    82  * <i>Minutes:</i>
    83  *         <i>Digit</i> <i>Digit</i>
    84  * <i>Digit:</i> one of
    85  *         <code>0 1 2 3 4 5 6 7 8 9</code>
    86  * </pre></blockquote>
    87  *
    88  * <i>Hours</i> must be between 0 to 23 and <i>Minutes</i> must be
    89  * between 00 to 59.  For example, "GMT+10" and "GMT+0010" mean ten
    90  * hours and ten minutes ahead of GMT, respectively.
    91  * <p>
    92  * The format is locale independent and digits must be taken from the
    93  * Basic Latin block of the Unicode standard. No daylight saving time
    94  * transition schedule can be specified with a custom time zone ID. If
    95  * the specified string doesn't match the syntax, <code>"GMT"</code>
    96  * is used.
    97  * <p>
    98  * When creating a <code>TimeZone</code>, the specified custom time
    99  * zone ID is normalized in the following syntax:
   100  * <blockquote><pre>
   101  * <a name="NormalizedCustomID"><i>NormalizedCustomID:</i></a>
   102  *         <code>GMT</code> <i>Sign</i> <i>TwoDigitHours</i> <code>:</code> <i>Minutes</i>
   103  * <i>Sign:</i> one of
   104  *         <code>+ -</code>
   105  * <i>TwoDigitHours:</i>
   106  *         <i>Digit</i> <i>Digit</i>
   107  * <i>Minutes:</i>
   108  *         <i>Digit</i> <i>Digit</i>
   109  * <i>Digit:</i> one of
   110  *         <code>0 1 2 3 4 5 6 7 8 9</code>
   111  * </pre></blockquote>
   112  * For example, TimeZone.getTimeZone("GMT-8").getID() returns "GMT-08:00".
   113  *
   114  * <h4>Three-letter time zone IDs</h4>
   115  *
   116  * For compatibility with JDK 1.1.x, some other three-letter time zone IDs
   117  * (such as "PST", "CTT", "AST") are also supported. However, <strong>their
   118  * use is deprecated</strong> because the same abbreviation is often used
   119  * for multiple time zones (for example, "CST" could be U.S. "Central Standard
   120  * Time" and "China Standard Time"), and the Java platform can then only
   121  * recognize one of them.
   122  *
   123  *
   124  * @see          Calendar
   125  * @see          GregorianCalendar
   126  * @see          SimpleTimeZone
   127  * @author       Mark Davis, David Goldsmith, Chen-Lieh Huang, Alan Liu
   128  * @since        JDK1.1
   129  */
   130 abstract public class TimeZone implements Serializable, Cloneable {
   131     /**
   132      * Sole constructor.  (For invocation by subclass constructors, typically
   133      * implicit.)
   134      */
   135     public TimeZone() {
   136     }
   137 
   138     /**
   139      * A style specifier for <code>getDisplayName()</code> indicating
   140      * a short name, such as "PST."
   141      * @see #LONG
   142      * @since 1.2
   143      */
   144     public static final int SHORT = 0;
   145 
   146     /**
   147      * A style specifier for <code>getDisplayName()</code> indicating
   148      * a long name, such as "Pacific Standard Time."
   149      * @see #SHORT
   150      * @since 1.2
   151      */
   152     public static final int LONG  = 1;
   153 
   154     // Constants used internally; unit is milliseconds
   155     private static final int ONE_MINUTE = 60*1000;
   156     private static final int ONE_HOUR   = 60*ONE_MINUTE;
   157     private static final int ONE_DAY    = 24*ONE_HOUR;
   158 
   159     // Proclaim serialization compatibility with JDK 1.1
   160     static final long serialVersionUID = 3581463369166924961L;
   161 
   162     /**
   163      * Gets the time zone offset, for current date, modified in case of
   164      * daylight savings. This is the offset to add to UTC to get local time.
   165      * <p>
   166      * This method returns a historically correct offset if an
   167      * underlying <code>TimeZone</code> implementation subclass
   168      * supports historical Daylight Saving Time schedule and GMT
   169      * offset changes.
   170      *
   171      * @param era the era of the given date.
   172      * @param year the year in the given date.
   173      * @param month the month in the given date.
   174      * Month is 0-based. e.g., 0 for January.
   175      * @param day the day-in-month of the given date.
   176      * @param dayOfWeek the day-of-week of the given date.
   177      * @param milliseconds the milliseconds in day in <em>standard</em>
   178      * local time.
   179      *
   180      * @return the offset in milliseconds to add to GMT to get local time.
   181      *
   182      * @see Calendar#ZONE_OFFSET
   183      * @see Calendar#DST_OFFSET
   184      */
   185     public abstract int getOffset(int era, int year, int month, int day,
   186                                   int dayOfWeek, int milliseconds);
   187 
   188     /**
   189      * Returns the offset of this time zone from UTC at the specified
   190      * date. If Daylight Saving Time is in effect at the specified
   191      * date, the offset value is adjusted with the amount of daylight
   192      * saving.
   193      * <p>
   194      * This method returns a historically correct offset value if an
   195      * underlying TimeZone implementation subclass supports historical
   196      * Daylight Saving Time schedule and GMT offset changes.
   197      *
   198      * @param date the date represented in milliseconds since January 1, 1970 00:00:00 GMT
   199      * @return the amount of time in milliseconds to add to UTC to get local time.
   200      *
   201      * @see Calendar#ZONE_OFFSET
   202      * @see Calendar#DST_OFFSET
   203      * @since 1.4
   204      */
   205     public int getOffset(long date) {
   206         if (inDaylightTime(new Date(date))) {
   207             return getRawOffset() + getDSTSavings();
   208         }
   209         return getRawOffset();
   210     }
   211 
   212     /**
   213      * Gets the raw GMT offset and the amount of daylight saving of this
   214      * time zone at the given time.
   215      * @param date the milliseconds (since January 1, 1970,
   216      * 00:00:00.000 GMT) at which the time zone offset and daylight
   217      * saving amount are found
   218      * @param offset an array of int where the raw GMT offset
   219      * (offset[0]) and daylight saving amount (offset[1]) are stored,
   220      * or null if those values are not needed. The method assumes that
   221      * the length of the given array is two or larger.
   222      * @return the total amount of the raw GMT offset and daylight
   223      * saving at the specified date.
   224      *
   225      * @see Calendar#ZONE_OFFSET
   226      * @see Calendar#DST_OFFSET
   227      */
   228     int getOffsets(long date, int[] offsets) {
   229         int rawoffset = getRawOffset();
   230         int dstoffset = 0;
   231         if (inDaylightTime(new Date(date))) {
   232             dstoffset = getDSTSavings();
   233         }
   234         if (offsets != null) {
   235             offsets[0] = rawoffset;
   236             offsets[1] = dstoffset;
   237         }
   238         return rawoffset + dstoffset;
   239     }
   240 
   241     /**
   242      * Sets the base time zone offset to GMT.
   243      * This is the offset to add to UTC to get local time.
   244      * <p>
   245      * If an underlying <code>TimeZone</code> implementation subclass
   246      * supports historical GMT offset changes, the specified GMT
   247      * offset is set as the latest GMT offset and the difference from
   248      * the known latest GMT offset value is used to adjust all
   249      * historical GMT offset values.
   250      *
   251      * @param offsetMillis the given base time zone offset to GMT.
   252      */
   253     abstract public void setRawOffset(int offsetMillis);
   254 
   255     /**
   256      * Returns the amount of time in milliseconds to add to UTC to get
   257      * standard time in this time zone. Because this value is not
   258      * affected by daylight saving time, it is called <I>raw
   259      * offset</I>.
   260      * <p>
   261      * If an underlying <code>TimeZone</code> implementation subclass
   262      * supports historical GMT offset changes, the method returns the
   263      * raw offset value of the current date. In Honolulu, for example,
   264      * its raw offset changed from GMT-10:30 to GMT-10:00 in 1947, and
   265      * this method always returns -36000000 milliseconds (i.e., -10
   266      * hours).
   267      *
   268      * @return the amount of raw offset time in milliseconds to add to UTC.
   269      * @see Calendar#ZONE_OFFSET
   270      */
   271     public abstract int getRawOffset();
   272 
   273     /**
   274      * Gets the ID of this time zone.
   275      * @return the ID of this time zone.
   276      */
   277     public String getID()
   278     {
   279         return ID;
   280     }
   281 
   282     /**
   283      * Sets the time zone ID. This does not change any other data in
   284      * the time zone object.
   285      * @param ID the new time zone ID.
   286      */
   287     public void setID(String ID)
   288     {
   289         if (ID == null) {
   290             throw new NullPointerException();
   291         }
   292         this.ID = ID;
   293     }
   294 
   295     /**
   296      * Returns a long standard time name of this {@code TimeZone} suitable for
   297      * presentation to the user in the default locale.
   298      *
   299      * <p>This method is equivalent to:
   300      * <pre><blockquote>
   301      * getDisplayName(false, {@link #LONG},
   302      *                Locale.getDefault({@link Locale.Category#DISPLAY}))
   303      * </blockquote></pre>
   304      *
   305      * @return the human-readable name of this time zone in the default locale.
   306      * @since 1.2
   307      * @see #getDisplayName(boolean, int, Locale)
   308      * @see Locale#getDefault(Locale.Category)
   309      * @see Locale.Category
   310      */
   311     public final String getDisplayName() {
   312         return getDisplayName(false, LONG,
   313                               Locale.getDefault(Locale.Category.DISPLAY));
   314     }
   315 
   316     /**
   317      * Returns a long standard time name of this {@code TimeZone} suitable for
   318      * presentation to the user in the specified {@code locale}.
   319      *
   320      * <p>This method is equivalent to:
   321      * <pre><blockquote>
   322      * getDisplayName(false, {@link #LONG}, locale)
   323      * </blockquote></pre>
   324      *
   325      * @param locale the locale in which to supply the display name.
   326      * @return the human-readable name of this time zone in the given locale.
   327      * @exception NullPointerException if {@code locale} is {@code null}.
   328      * @since 1.2
   329      * @see #getDisplayName(boolean, int, Locale)
   330      */
   331     public final String getDisplayName(Locale locale) {
   332         return getDisplayName(false, LONG, locale);
   333     }
   334 
   335     /**
   336      * Returns a name in the specified {@code style} of this {@code TimeZone}
   337      * suitable for presentation to the user in the default locale. If the
   338      * specified {@code daylight} is {@code true}, a Daylight Saving Time name
   339      * is returned (even if this {@code TimeZone} doesn't observe Daylight Saving
   340      * Time). Otherwise, a Standard Time name is returned.
   341      *
   342      * <p>This method is equivalent to:
   343      * <pre><blockquote>
   344      * getDisplayName(daylight, style,
   345      *                Locale.getDefault({@link Locale.Category#DISPLAY}))
   346      * </blockquote></pre>
   347      *
   348      * @param daylight {@code true} specifying a Daylight Saving Time name, or
   349      *                 {@code false} specifying a Standard Time name
   350      * @param style either {@link #LONG} or {@link #SHORT}
   351      * @return the human-readable name of this time zone in the default locale.
   352      * @exception IllegalArgumentException if {@code style} is invalid.
   353      * @since 1.2
   354      * @see #getDisplayName(boolean, int, Locale)
   355      * @see Locale#getDefault(Locale.Category)
   356      * @see Locale.Category
   357      * @see java.text.DateFormatSymbols#getZoneStrings()
   358      */
   359     public final String getDisplayName(boolean daylight, int style) {
   360         return getDisplayName(daylight, style,
   361                               Locale.getDefault(Locale.Category.DISPLAY));
   362     }
   363 
   364     /**
   365      * Returns a name in the specified {@code style} of this {@code TimeZone}
   366      * suitable for presentation to the user in the specified {@code
   367      * locale}. If the specified {@code daylight} is {@code true}, a Daylight
   368      * Saving Time name is returned (even if this {@code TimeZone} doesn't
   369      * observe Daylight Saving Time). Otherwise, a Standard Time name is
   370      * returned.
   371      *
   372      * <p>When looking up a time zone name, the {@linkplain
   373      * ResourceBundle.Control#getCandidateLocales(String,Locale) default
   374      * <code>Locale</code> search path of <code>ResourceBundle</code>} derived
   375      * from the specified {@code locale} is used. (No {@linkplain
   376      * ResourceBundle.Control#getFallbackLocale(String,Locale) fallback
   377      * <code>Locale</code>} search is performed.) If a time zone name in any
   378      * {@code Locale} of the search path, including {@link Locale#ROOT}, is
   379      * found, the name is returned. Otherwise, a string in the
   380      * <a href="#NormalizedCustomID">normalized custom ID format</a> is returned.
   381      *
   382      * @param daylight {@code true} specifying a Daylight Saving Time name, or
   383      *                 {@code false} specifying a Standard Time name
   384      * @param style either {@link #LONG} or {@link #SHORT}
   385      * @param locale   the locale in which to supply the display name.
   386      * @return the human-readable name of this time zone in the given locale.
   387      * @exception IllegalArgumentException if {@code style} is invalid.
   388      * @exception NullPointerException if {@code locale} is {@code null}.
   389      * @since 1.2
   390      * @see java.text.DateFormatSymbols#getZoneStrings()
   391      */
   392     public String getDisplayName(boolean daylight, int style, Locale locale) {
   393         if (style != SHORT && style != LONG) {
   394             throw new IllegalArgumentException("Illegal style: " + style);
   395         }
   396 
   397         String id = getID();
   398         String[] names = getDisplayNames(id, locale);
   399         if (names == null) {
   400             if (id.startsWith("GMT")) {
   401                 char sign = id.charAt(3);
   402                 if (sign == '+' || sign == '-') {
   403                     return id;
   404                 }
   405             }
   406             int offset = getRawOffset();
   407             if (daylight) {
   408                 offset += getDSTSavings();
   409             }
   410           //  return ZoneInfoFile.toCustomID(offset);
   411         }
   412 
   413         int index = daylight ? 3 : 1;
   414         if (style == SHORT) {
   415             index++;
   416         }
   417         return names[index];
   418     }
   419 
   420     private static class DisplayNames {
   421         // Cache for managing display names per timezone per locale
   422         // The structure is:
   423         //   Map(key=id, value=SoftReference(Map(key=locale, value=displaynames)))
   424         private static final Map<String, SoftReference<Map<Locale, String[]>>> CACHE =
   425             new ConcurrentHashMap<String, SoftReference<Map<Locale, String[]>>>();
   426     }
   427 
   428     private static final String[] getDisplayNames(String id, Locale locale) {
   429         Map<String, SoftReference<Map<Locale, String[]>>> displayNames = DisplayNames.CACHE;
   430 
   431         SoftReference<Map<Locale, String[]>> ref = displayNames.get(id);
   432         if (ref != null) {
   433             Map<Locale, String[]> perLocale = ref.get();
   434             if (perLocale != null) {
   435                 String[] names = perLocale.get(locale);
   436                 if (names != null) {
   437                     return names;
   438                 }
   439                 names = null; // TimeZoneNameUtility.retrieveDisplayNames(id, locale);
   440                 if (names != null) {
   441                     perLocale.put(locale, names);
   442                 }
   443                 return names;
   444             }
   445         }
   446 
   447         String[] names = null; // TimeZoneNameUtility.retrieveDisplayNames(id, locale);
   448         if (names != null) {
   449             Map<Locale, String[]> perLocale = new ConcurrentHashMap<Locale, String[]>();
   450             perLocale.put(locale, names);
   451             ref = new SoftReference<Map<Locale, String[]>>(perLocale);
   452             displayNames.put(id, ref);
   453         }
   454         return names;
   455     }
   456 
   457     /**
   458      * Returns the amount of time to be added to local standard time
   459      * to get local wall clock time.
   460      *
   461      * <p>The default implementation returns 3600000 milliseconds
   462      * (i.e., one hour) if a call to {@link #useDaylightTime()}
   463      * returns {@code true}. Otherwise, 0 (zero) is returned.
   464      *
   465      * <p>If an underlying {@code TimeZone} implementation subclass
   466      * supports historical and future Daylight Saving Time schedule
   467      * changes, this method returns the amount of saving time of the
   468      * last known Daylight Saving Time rule that can be a future
   469      * prediction.
   470      *
   471      * <p>If the amount of saving time at any given time stamp is
   472      * required, construct a {@link Calendar} with this {@code
   473      * TimeZone} and the time stamp, and call {@link Calendar#get(int)
   474      * Calendar.get}{@code (}{@link Calendar#DST_OFFSET}{@code )}.
   475      *
   476      * @return the amount of saving time in milliseconds
   477      * @since 1.4
   478      * @see #inDaylightTime(Date)
   479      * @see #getOffset(long)
   480      * @see #getOffset(int,int,int,int,int,int)
   481      * @see Calendar#ZONE_OFFSET
   482      */
   483     public int getDSTSavings() {
   484         if (useDaylightTime()) {
   485             return 3600000;
   486         }
   487         return 0;
   488     }
   489 
   490     /**
   491      * Queries if this {@code TimeZone} uses Daylight Saving Time.
   492      *
   493      * <p>If an underlying {@code TimeZone} implementation subclass
   494      * supports historical and future Daylight Saving Time schedule
   495      * changes, this method refers to the last known Daylight Saving Time
   496      * rule that can be a future prediction and may not be the same as
   497      * the current rule. Consider calling {@link #observesDaylightTime()}
   498      * if the current rule should also be taken into account.
   499      *
   500      * @return {@code true} if this {@code TimeZone} uses Daylight Saving Time,
   501      *         {@code false}, otherwise.
   502      * @see #inDaylightTime(Date)
   503      * @see Calendar#DST_OFFSET
   504      */
   505     public abstract boolean useDaylightTime();
   506 
   507     /**
   508      * Returns {@code true} if this {@code TimeZone} is currently in
   509      * Daylight Saving Time, or if a transition from Standard Time to
   510      * Daylight Saving Time occurs at any future time.
   511      *
   512      * <p>The default implementation returns {@code true} if
   513      * {@code useDaylightTime()} or {@code inDaylightTime(new Date())}
   514      * returns {@code true}.
   515      *
   516      * @return {@code true} if this {@code TimeZone} is currently in
   517      * Daylight Saving Time, or if a transition from Standard Time to
   518      * Daylight Saving Time occurs at any future time; {@code false}
   519      * otherwise.
   520      * @since 1.7
   521      * @see #useDaylightTime()
   522      * @see #inDaylightTime(Date)
   523      * @see Calendar#DST_OFFSET
   524      */
   525     public boolean observesDaylightTime() {
   526         return useDaylightTime() || inDaylightTime(new Date());
   527     }
   528 
   529     /**
   530      * Queries if the given {@code date} is in Daylight Saving Time in
   531      * this time zone.
   532      *
   533      * @param date the given Date.
   534      * @return {@code true} if the given date is in Daylight Saving Time,
   535      *         {@code false}, otherwise.
   536      */
   537     abstract public boolean inDaylightTime(Date date);
   538 
   539     /**
   540      * Gets the <code>TimeZone</code> for the given ID.
   541      *
   542      * @param ID the ID for a <code>TimeZone</code>, either an abbreviation
   543      * such as "PST", a full name such as "America/Los_Angeles", or a custom
   544      * ID such as "GMT-8:00". Note that the support of abbreviations is
   545      * for JDK 1.1.x compatibility only and full names should be used.
   546      *
   547      * @return the specified <code>TimeZone</code>, or the GMT zone if the given ID
   548      * cannot be understood.
   549      */
   550     public static synchronized TimeZone getTimeZone(String ID) {
   551         return getTimeZone(ID, true);
   552     }
   553 
   554     private static TimeZone getTimeZone(String ID, boolean fallback) {
   555 //        TimeZone tz = ZoneInfo.getTimeZone(ID);
   556 //        if (tz == null) {
   557 //            tz = parseCustomTimeZone(ID);
   558 //            if (tz == null && fallback) {
   559 //                tz = new ZoneInfo(GMT_ID, 0);
   560 //            }
   561 //        }
   562 //        return tz;
   563         return TimeZone.NO_TIMEZONE;
   564     }
   565 
   566     /**
   567      * Gets the available IDs according to the given time zone offset in milliseconds.
   568      *
   569      * @param rawOffset the given time zone GMT offset in milliseconds.
   570      * @return an array of IDs, where the time zone for that ID has
   571      * the specified GMT offset. For example, "America/Phoenix" and "America/Denver"
   572      * both have GMT-07:00, but differ in daylight saving behavior.
   573      * @see #getRawOffset()
   574      */
   575     public static synchronized String[] getAvailableIDs(int rawOffset) {
   576         return new String[0];//ZoneInfo.getAvailableIDs(rawOffset);
   577     }
   578 
   579     /**
   580      * Gets all the available IDs supported.
   581      * @return an array of IDs.
   582      */
   583     public static synchronized String[] getAvailableIDs() {
   584         return new String[0];//return ZoneInfo.getAvailableIDs();
   585     }
   586 
   587     /**
   588      * Gets the platform defined TimeZone ID.
   589      **/
   590     private static native String getSystemTimeZoneID(String javaHome,
   591                                                      String country);
   592 
   593     /**
   594      * Gets the custom time zone ID based on the GMT offset of the
   595      * platform. (e.g., "GMT+08:00")
   596      */
   597     private static native String getSystemGMTOffsetID();
   598 
   599     /**
   600      * Gets the default <code>TimeZone</code> for this host.
   601      * The source of the default <code>TimeZone</code>
   602      * may vary with implementation.
   603      * @return a default <code>TimeZone</code>.
   604      * @see #setDefault
   605      */
   606     public static TimeZone getDefault() {
   607         return (TimeZone) getDefaultRef().clone();
   608     }
   609 
   610     /**
   611      * Returns the reference to the default TimeZone object. This
   612      * method doesn't create a clone.
   613      */
   614     static TimeZone getDefaultRef() {
   615         TimeZone defaultZone = null;//defaultZoneTL.get();
   616         if (defaultZone == null) {
   617             defaultZone = defaultTimeZone;
   618             if (defaultZone == null) {
   619                 // Need to initialize the default time zone.
   620                 defaultZone = TimeZone.NO_TIMEZONE;
   621                 assert defaultZone != null;
   622             }
   623         }
   624         // Don't clone here.
   625         return defaultZone;
   626     }
   627 
   628     private static boolean hasPermission() {
   629         boolean hasPermission = false;
   630         return hasPermission;
   631     }
   632 
   633     /**
   634      * Sets the <code>TimeZone</code> that is
   635      * returned by the <code>getDefault</code> method.  If <code>zone</code>
   636      * is null, reset the default to the value it had originally when the
   637      * VM first started.
   638      * @param zone the new default time zone
   639      * @see #getDefault
   640      */
   641     public static void setDefault(TimeZone zone)
   642     {
   643         if (hasPermission()) {
   644             synchronized (TimeZone.class) {
   645                 defaultTimeZone = zone;
   646               //  defaultZoneTL.set(null);
   647             }
   648         } else {
   649             //defaultZoneTL.set(zone);
   650         }
   651     }
   652 
   653     /**
   654      * Returns true if this zone has the same rule and offset as another zone.
   655      * That is, if this zone differs only in ID, if at all.  Returns false
   656      * if the other zone is null.
   657      * @param other the <code>TimeZone</code> object to be compared with
   658      * @return true if the other zone is not null and is the same as this one,
   659      * with the possible exception of the ID
   660      * @since 1.2
   661      */
   662     public boolean hasSameRules(TimeZone other) {
   663         return other != null && getRawOffset() == other.getRawOffset() &&
   664             useDaylightTime() == other.useDaylightTime();
   665     }
   666 
   667     /**
   668      * Creates a copy of this <code>TimeZone</code>.
   669      *
   670      * @return a clone of this <code>TimeZone</code>
   671      */
   672     public Object clone()
   673     {
   674         try {
   675             TimeZone other = (TimeZone) super.clone();
   676             other.ID = ID;
   677             return other;
   678         } catch (CloneNotSupportedException e) {
   679             throw new InternalError();
   680         }
   681     }
   682 
   683     /**
   684      * The null constant as a TimeZone.
   685      */
   686     static final TimeZone NO_TIMEZONE = null;
   687 
   688     // =======================privates===============================
   689 
   690     /**
   691      * The string identifier of this <code>TimeZone</code>.  This is a
   692      * programmatic identifier used internally to look up <code>TimeZone</code>
   693      * objects from the system table and also to map them to their localized
   694      * display names.  <code>ID</code> values are unique in the system
   695      * table but may not be for dynamically created zones.
   696      * @serial
   697      */
   698     private String           ID;
   699     private static volatile TimeZone defaultTimeZone;
   700 
   701     static final String         GMT_ID        = "GMT";
   702     private static final int    GMT_ID_LENGTH = 3;
   703 
   704     /**
   705      * Parses a custom time zone identifier and returns a corresponding zone.
   706      * This method doesn't support the RFC 822 time zone format. (e.g., +hhmm)
   707      *
   708      * @param id a string of the <a href="#CustomID">custom ID form</a>.
   709      * @return a newly created TimeZone with the given offset and
   710      * no daylight saving time, or null if the id cannot be parsed.
   711      */
   712     private static final TimeZone parseCustomTimeZone(String id) {
   713         return null;
   714     }
   715 }