Class ZoneRegion
- java.lang.Object
-
- org.threeten.bp.ZoneId
-
- org.threeten.bp.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.StringidThe time-zone ID, not null.private static java.util.regex.PatternPATTERNThe regex pattern for region IDs.private ZoneRulesrulesThe time-zone rules, null if zone ID was loaded leniently.private static longserialVersionUIDSerialization version.
-
Constructor Summary
Constructors Constructor Description ZoneRegion(java.lang.String id, ZoneRules rules)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetId()Gets the unique time-zone ID.ZoneRulesgetRules()Gets the time-zone rules for this ID allowing calculations to be performed.(package private) static ZoneRegionofId(java.lang.String zoneId, boolean checkAvailable)Obtains an instance ofZoneIdfrom an identifier.private static ZoneRegionofLenient(java.lang.String zoneId)Obtains an instance ofZoneRegionfrom an identifier without checking if the time-zone has available rules.(package private) static ZoneIdreadExternal(java.io.DataInput in)private java.lang.ObjectreadResolve()Defend against malicious streams.(package private) voidwrite(java.io.DataOutput out)(package private) voidwriteExternal(java.io.DataOutput out)private java.lang.ObjectwriteReplace()-
Methods inherited from class org.threeten.bp.ZoneId
equals, from, getAvailableZoneIds, getDisplayName, hashCode, normalized, of, of, ofOffset, systemDefault, toString
-
-
-
-
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 nullrules- the rules, null for lazy lookup
-
-
Method Detail
-
ofLenient
private static ZoneRegion ofLenient(java.lang.String zoneId)
Obtains an instance ofZoneRegionfrom 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 aZonedDateTime, 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 ofZoneIdfrom an identifier.- Parameters:
zoneId- the time-zone ID, not nullcheckAvailable- whether to check if the zone ID is available- Returns:
- the zone ID, not null
- Throws:
DateTimeException- if the ID format is invalidDateTimeException- if checking availability and the ID cannot be found
-
getId
public java.lang.String getId()
Description copied from class:ZoneIdGets the unique time-zone ID.This ID uniquely defines this object. The format of an offset based ID is defined by
ZoneOffset.getId().
-
getRules
public ZoneRules getRules()
Description copied from class:ZoneIdGets 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.ZoneOffsetwill always return a set of rules where the offset never changes.
-
writeReplace
private java.lang.Object writeReplace()
-
readResolve
private java.lang.Object readResolve() throws java.io.ObjectStreamExceptionDefend against malicious streams.- Returns:
- never
- Throws:
java.io.InvalidObjectException- alwaysjava.io.ObjectStreamException
-
write
void write(java.io.DataOutput out) 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
-
-