Ejemplo n.º 1
0
  /**
   * Sets the <code>TimeZone</code> that is returned by the <code>getDefault</code> method. If
   * <code>zone</code> is null, reset the default to the value it had originally when the VM first
   * started.
   *
   * @param tz the new default time zone
   * @stable ICU 2.0
   */
  public static synchronized void setDefault(TimeZone tz) {
    defaultZone = tz;
    java.util.TimeZone jdkZone = null;
    if (defaultZone instanceof JavaTimeZone) {
      jdkZone = ((JavaTimeZone) defaultZone).unwrap();
    } else {
      // Keep java.util.TimeZone default in sync so java.util.Date
      // can interoperate with com.ibm.icu.util classes.

      if (tz != null) {
        if (tz instanceof com.ibm.icu.impl.OlsonTimeZone) {
          // Because of the lack of APIs supporting historic
          // zone offset/dst saving in JDK TimeZone,
          // wrapping ICU TimeZone with JDK TimeZone will
          // cause historic offset calculation in Calendar/Date.
          // JDK calendar implementation calls getRawOffset() and
          // getDSTSavings() when the instance of JDK TimeZone
          // is not an instance of JDK internal TimeZone subclass
          // (sun.util.calendar.ZoneInfo).  Ticket#6459
          String icuID = tz.getID();
          jdkZone = java.util.TimeZone.getTimeZone(icuID);
          if (!icuID.equals(jdkZone.getID())) {
            // JDK does not know the ID..
            jdkZone = null;
          }
        }
        if (jdkZone == null) {
          jdkZone = TimeZoneAdapter.wrap(tz);
        }
      }
    }
    java.util.TimeZone.setDefault(jdkZone);
  }