Class JavaTimeZone

java.lang.Object
com.ibm.icu.util.TimeZone
com.ibm.icu.impl.JavaTimeZone
All Implemented Interfaces:
Freezable<TimeZone>, Serializable, Cloneable

public class JavaTimeZone extends TimeZone
JavaTimeZone inherits com.ibm.icu.util.TimeZone and wraps java.util.TimeZone. We used to have JDKTimeZone which wrapped Java TimeZone and used it as primary TimeZone implementation until ICU4J 3.4.1. This class works exactly like JDKTimeZone and allows ICU users who use ICU4J and JDK date/time/calendar services in mix to maintain only JDK timezone rules. This TimeZone subclass is returned by the TimeZone factory method getTimeZone(String) when the default timezone type in TimeZone class is TimeZone.TIMEZONE_JDK.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • AVAILABLESET

      private static final TreeSet<String> AVAILABLESET
    • javatz

      private TimeZone javatz
    • javacal

      private transient Calendar javacal
    • mObservesDaylightTime

      private static Method mObservesDaylightTime
    • isFrozen

      private transient volatile boolean isFrozen
  • Constructor Details

    • JavaTimeZone

      public JavaTimeZone()
      Constructs a JavaTimeZone with the default Java TimeZone
    • JavaTimeZone

      public JavaTimeZone(TimeZone jtz, String id)
      Constructs a JavaTimeZone with the specified Java TimeZone and ID.
      Parameters:
      jtz - the Java TimeZone
      id - the ID of the zone. if null, the zone ID is initialized by the given Java TimeZone's ID.
  • Method Details

    • createTimeZone

      public static JavaTimeZone createTimeZone(String id)
      Creates an instance of JavaTimeZone with the given timezone ID.
      Parameters:
      id - A timezone ID, either a system ID or a custom ID.
      Returns:
      An instance of JavaTimeZone for the given ID, or null when the ID cannot be understood.
    • getOffset

      public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds)
      Description copied from class: TimeZone
      Gets the time zone offset, for current date, modified in case of daylight savings. This is the offset to add to UTC to get local time.
      Specified by:
      getOffset in class TimeZone
      Parameters:
      era - the era of the given date.
      year - the year in the given date.
      month - the month in the given date. Month is 0-based. e.g., 0 for January.
      day - the day-in-month of the given date.
      dayOfWeek - the day-of-week of the given date.
      milliseconds - the millis in day in standard local time.
      Returns:
      the offset to add to GMT to get local time.
    • getOffset

      public void getOffset(long date, boolean local, int[] offsets)
      Description copied from class: TimeZone
      Returns the time zone raw and GMT offset for the given moment in time. Upon return, local-millis = GMT-millis + rawOffset + dstOffset. All computations are performed in the proleptic Gregorian calendar. The default implementation in the TimeZone class delegates to the 8-argument getOffset().
      Overrides:
      getOffset in class TimeZone
      Parameters:
      date - moment in time for which to return offsets, in units of milliseconds from January 1, 1970 0:00 GMT, either GMT time or local wall time, depending on local.
      local - if true, date is local wall time; otherwise it is in GMT time.
      offsets - output parameter to receive the raw offset, that is, the offset not including DST adjustments, in offsets[0], and the DST offset, that is, the offset to be added to rawOffset to obtain the total offset between local and GMT time, in offsets[1]. If DST is not in effect, the DST offset is zero; otherwise it is a positive value, typically one hour.
    • getRawOffset

      public int getRawOffset()
      Description copied from class: TimeZone
      Gets unmodified offset, NOT modified in case of daylight savings. This is the offset to add to UTC to get local time.
      Specified by:
      getRawOffset in class TimeZone
      Returns:
      the unmodified offset to add to UTC to get local time.
    • inDaylightTime

      public boolean inDaylightTime(Date date)
      Description copied from class: TimeZone
      Queries if the given date is in daylight savings time in this time zone.
      Specified by:
      inDaylightTime in class TimeZone
      Parameters:
      date - the given Date.
      Returns:
      true if the given date is in daylight savings time, false, otherwise.
    • setRawOffset

      public void setRawOffset(int offsetMillis)
      Description copied from class: TimeZone
      Sets the base time zone offset to GMT. This is the offset to add to UTC to get local time.
      Specified by:
      setRawOffset in class TimeZone
      Parameters:
      offsetMillis - the given base time zone offset to GMT.
    • useDaylightTime

      public boolean useDaylightTime()
      Description copied from class: TimeZone
      Queries if this time zone uses daylight savings time.
      Specified by:
      useDaylightTime in class TimeZone
      Returns:
      true if this time zone uses daylight savings time, false, otherwise.

      Note:The default implementation of ICU TimeZone uses the tz database, which supports historic rule changes, for system time zones. With the implementation, there are time zones that used daylight savings time in the past, but no longer used currently. For example, Asia/Tokyo has never used daylight savings time since 1951. Most clients would expect that this method to return false for such case. The default implementation of this method returns true when the time zone uses daylight savings time in the current (Gregorian) calendar year.

    • observesDaylightTime

      public boolean observesDaylightTime()
      Description copied from class: TimeZone
      Queries if this time zone is in daylight saving time or will observe daylight saving time at any future time.

      The default implementation in this class returns true if TimeZone.useDaylightTime() or inDaylightTime(new Date()) returns true.

      Note: This method was added for TimeZone compatibility support. The TimeZone.useDaylightTime() method only checks the last known rule(s), therefore it may return false even the zone observes daylight saving time currently. TimeZone added observesDaylightTime() to resolve the issue. In ICU, TimeZone.useDaylightTime() works differently. The ICU implementation checks if the zone uses daylight saving time in the current calendar year. Therefore, it will never return false if daylight saving time is currently used.

      ICU's TimeZone subclass implementations override this method to support the same behavior with TimeZone.observesDaylightTime(). Unlike TimeZone.useDaylightTime(), the implementation does not take past daylight saving time into account, so that this method may return false even when TimeZone.useDaylightTime() returns true.

      Overrides:
      observesDaylightTime in class TimeZone
      Returns:
      true if this time zone is in daylight saving time or will observe daylight saving time at any future time.
      See Also:
    • getDSTSavings

      public int getDSTSavings()
      Description copied from class: TimeZone
      Returns the amount of time to be added to local standard time to get local wall clock time.

      The default implementation always returns 3600000 milliseconds (i.e., one hour) if this time zone observes Daylight Saving Time. Otherwise, 0 (zero) is returned.

      If an underlying TimeZone implementation subclass supports historical Daylight Saving Time changes, this method returns the known latest daylight saving value.

      Overrides:
      getDSTSavings in class TimeZone
      Returns:
      the amount of saving time in milliseconds
    • unwrap

      public TimeZone unwrap()
    • clone

      public Object clone()
      Description copied from class: TimeZone
      Overrides clone.
      Overrides:
      clone in class TimeZone
    • hashCode

      public int hashCode()
      Description copied from class: TimeZone
      Overrides hashCode.
      Overrides:
      hashCode in class TimeZone
      Returns:
      a hash code value for this object.
    • readObject

      private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
      Throws:
      IOException
      ClassNotFoundException
    • isFrozen

      public boolean isFrozen()
      Description copied from class: TimeZone
      Determines whether the object has been frozen or not.
      Specified by:
      isFrozen in interface Freezable<TimeZone>
      Overrides:
      isFrozen in class TimeZone
    • freeze

      public TimeZone freeze()
      Description copied from class: TimeZone
      Freezes the object.
      Specified by:
      freeze in interface Freezable<TimeZone>
      Overrides:
      freeze in class TimeZone
      Returns:
      the object itself.
    • cloneAsThawed

      public TimeZone cloneAsThawed()
      Description copied from class: TimeZone
      Provides for the clone operation. Any clone is initially unfrozen.
      Specified by:
      cloneAsThawed in interface Freezable<TimeZone>
      Overrides:
      cloneAsThawed in class TimeZone