Class ZoneRegion
- All Implemented Interfaces:
Serializable
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetId()Gets the unique time-zone ID.getRules()Gets the time-zone rules for this ID allowing calculations to be performed.(package private) static ZoneRegionObtains an instance ofZoneIdfrom an identifier.private static ZoneRegionObtains an instance ofZoneRegionfrom an identifier without checking if the time-zone has available rules.(package private) static ZoneIdprivate ObjectDefend against malicious streams.(package private) voidwrite(DataOutput out) (package private) voidwriteExternal(DataOutput out) private ObjectMethods inherited from class org.threeten.bp.ZoneId
equals, from, getAvailableZoneIds, getDisplayName, hashCode, normalized, of, of, ofOffset, systemDefault, toString
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization version.- See Also:
-
PATTERN
The regex pattern for region IDs. -
id
The time-zone ID, not null. -
rules
The time-zone rules, null if zone ID was loaded leniently.
-
-
Constructor Details
-
ZoneRegion
Constructor.- Parameters:
id- the time-zone ID, not nullrules- the rules, null for lazy lookup
-
-
Method Details
-
ofLenient
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
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
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
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
-
readResolve
Defend against malicious streams.- Returns:
- never
- Throws:
InvalidObjectException- alwaysObjectStreamException
-
write
- Specified by:
writein classZoneId- Throws:
IOException
-
writeExternal
- Throws:
IOException
-
readExternal
- Throws:
IOException
-