Class ZoneRegion

java.lang.Object
org.threeten.bp.ZoneId
org.threeten.bp.ZoneRegion
All Implemented Interfaces:
Serializable

final class ZoneRegion extends ZoneId implements Serializable
A geographical region where the same time-zone rules apply.

Time-zone information is categorized as a set of rules defining when and how the offset from UTC/Greenwich changes. These rules are accessed using identifiers based on geographical regions, such as countries or states. The most common region classification is the Time Zone Database (TZDB), which defines regions such as 'Europe/Paris' and 'Asia/Tokyo'.

The region identifier, modeled by this class, is distinct from the underlying rules, modeled by ZoneRules. The rules are defined by governments and change frequently. By contrast, the region identifier is well-defined and long-lived. This separation also allows rules to be shared between regions if appropriate.

Specification for implementors

This class is immutable and thread-safe.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version.
      See Also:
    • PATTERN

      private static final Pattern PATTERN
      The regex pattern for region IDs.
    • id

      private final String id
      The time-zone ID, not null.
    • rules

      private final transient ZoneRules rules
      The time-zone rules, null if zone ID was loaded leniently.
  • Constructor Details

    • ZoneRegion

      ZoneRegion(String id, ZoneRules rules)
      Constructor.
      Parameters:
      id - the time-zone ID, not null
      rules - the rules, null for lazy lookup
  • Method Details

    • ofLenient

      private static ZoneRegion ofLenient(String zoneId)
      Obtains an instance of ZoneRegion from an identifier without checking if the time-zone has available rules.

      This method parses the ID and applies any appropriate normalization. It does not validate the ID against the known set of IDsfor which rules are available.

      This method is intended for advanced use cases. For example, consider a system that always retrieves time-zone rules from a remote server. Using this factory would allow a ZoneRegion, and thus a ZonedDateTime, to be created without loading the rules from the remote server.

      Parameters:
      zoneId - the time-zone ID, not null
      Returns:
      the zone ID, not null
      Throws:
      DateTimeException - if the ID format is invalid
    • ofId

      static ZoneRegion ofId(String zoneId, boolean checkAvailable)
      Obtains an instance of ZoneId from an identifier.
      Parameters:
      zoneId - the time-zone ID, not null
      checkAvailable - whether to check if the zone ID is available
      Returns:
      the zone ID, not null
      Throws:
      DateTimeException - if the ID format is invalid
      DateTimeException - if checking availability and the ID cannot be found
    • getId

      public String getId()
      Description copied from class: ZoneId
      Gets the unique time-zone ID.

      This ID uniquely defines this object. The format of an offset based ID is defined by ZoneOffset.getId().

      Specified by:
      getId in class ZoneId
      Returns:
      the time-zone unique ID, not null
    • getRules

      public ZoneRules getRules()
      Description copied from class: ZoneId
      Gets the time-zone rules for this ID allowing calculations to be performed.

      The rules provide the functionality associated with a time-zone, such as finding the offset for a given instant or local date-time.

      A time-zone can be invalid if it is deserialized in a Java Runtime which does not have the same rules loaded as the Java Runtime that stored it. In this case, calling this method will throw a ZoneRulesException.

      The rules are supplied by ZoneRulesProvider. An advanced provider may support dynamic updates to the rules without restarting the Java Runtime. If so, then the result of this method may change over time. Each individual call will be still remain thread-safe.

      ZoneOffset will always return a set of rules where the offset never changes.

      Specified by:
      getRules in class ZoneId
      Returns:
      the rules, not null
    • writeReplace

      private Object writeReplace()
    • readResolve

      private Object readResolve() throws ObjectStreamException
      Defend against malicious streams.
      Returns:
      never
      Throws:
      InvalidObjectException - always
      ObjectStreamException
    • write

      void write(DataOutput out) throws IOException
      Specified by:
      write in class ZoneId
      Throws:
      IOException
    • writeExternal

      void writeExternal(DataOutput out) throws IOException
      Throws:
      IOException
    • readExternal

      static ZoneId readExternal(DataInput in) throws IOException
      Throws:
      IOException