Class ZoneRegion

  • All Implemented Interfaces:
    java.io.Serializable

    final class ZoneRegion
    extends ZoneId
    implements java.io.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 Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String id
      The time-zone ID, not null.
      private static java.util.regex.Pattern PATTERN
      The regex pattern for region IDs.
      private ZoneRules rules
      The time-zone rules, null if zone ID was loaded leniently.
      private static long serialVersionUID
      Serialization version.
    • Constructor Summary

      Constructors 
      Constructor Description
      ZoneRegion​(java.lang.String id, ZoneRules rules)
      Constructor.
    • Field Detail

      • serialVersionUID

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

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

        private final java.lang.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 Detail

      • ZoneRegion

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

      • ofLenient

        private static ZoneRegion ofLenient​(java.lang.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​(java.lang.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 java.lang.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 java.lang.Object writeReplace()
      • readResolve

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

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

        void writeExternal​(java.io.DataOutput out)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readExternal

        static ZoneId readExternal​(java.io.DataInput in)
                            throws java.io.IOException
        Throws:
        java.io.IOException