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