public abstract class ZoneRules extends Object
The rules model all the historic and future transitions for a time-zone.
The rules are loaded via TimeZone
and ZoneRulesGroup
and
are specific to a group, region and version. The same rules may be shared
between multiple versions, regions or even groups.
Serializing an instance of ZoneRules
will store the entire set
of rules. It does not store the group, region or version as they are not
part of the state of this object.
ZoneRules is an abstract class and must be implemented with care to ensure other classes in the framework operate correctly. All instantiable implementations must be final, immutable and thread-safe. It is only intended that the abstract methods are overridden. Subclasses should be Serializable wherever possible.
Modifier | Constructor and Description |
---|---|
protected |
ZoneRules()
Constructor for subclasses.
|
Modifier and Type | Method and Description |
---|---|
abstract boolean |
equals(Object otherRules)
Checks if this set of rules equals another.
|
Period |
getDaylightSavings(InstantProvider instantProvider)
Gets the amount of daylight savings in use for the specified instant in this zone.
|
abstract ZoneOffset |
getOffset(InstantProvider instant)
Gets the offset applicable at the specified instant in this zone.
|
ZoneOffsetInfo |
getOffsetInfo(Instant instant)
Gets the offset information for the specified instant in this zone.
|
abstract ZoneOffsetInfo |
getOffsetInfo(LocalDateTime dateTime)
Gets the offset information for a local date-time in this zone.
|
abstract ZoneOffset |
getStandardOffset(InstantProvider instantProvider)
Gets the standard offset for the specified instant in this zone.
|
abstract List<ZoneOffsetTransitionRule> |
getTransitionRules()
Gets the list of transition rules for years beyond those defined in the transition list.
|
abstract List<ZoneOffsetTransition> |
getTransitions()
Gets the complete list of fully defined transitions.
|
abstract int |
hashCode()
Returns a suitable hash code.
|
boolean |
isDaylightSavings(InstantProvider instant)
Gets the standard offset for the specified instant in this zone.
|
boolean |
isFixedOffset()
Checks of the zone rules are fixed, such that the offset never varies.
|
boolean |
isValidDateTime(OffsetDateTime dateTime)
Checks if the offset date-time is valid for these rules.
|
abstract ZoneOffsetTransition |
nextTransition(InstantProvider instantProvider)
Gets the next transition after the specified transition.
|
static ZoneRules |
ofFixed(ZoneOffset offset)
Obtains a rules instance for a specific offset.
|
abstract ZoneOffsetTransition |
previousTransition(InstantProvider instantProvider)
Gets the previous transition after the specified transition.
|
public static ZoneRules ofFixed(ZoneOffset offset)
The returned rules object will have no transitions and will use the specified offset for all points on the time-line.
offset
- the offset to get the fixed rules for, not nullpublic boolean isFixedOffset()
It is intended that OffsetDateTime
, OffsetDate
and
OffsetTime
are used in preference to fixed offset time-zones
in ZonedDateTime
.
The default implementation returns false.
public abstract ZoneOffset getOffset(InstantProvider instant)
For any given instant there can only ever be one valid offset, which
is returned by this method. To access more detailed information about
the offset at and around the instant use getOffsetInfo(Instant)
.
instant
- the instant to find the offset for,
ignored for fixed offset rules, otherwise not nullpublic ZoneOffsetInfo getOffsetInfo(Instant instant)
This provides access to full details as to the offset or offsets applicable for the local date-time. The mapping from an instant to an offset is not straightforward. There are two cases:
ZoneOffsetInfo.isTransition()
to handle the overlap.instant
- the instant to find the offset information for, not nullpublic abstract ZoneOffsetInfo getOffsetInfo(LocalDateTime dateTime)
This provides access to full details as to the offset or offsets applicable for the local date-time. The mapping from a local date-time to an offset is not straightforward. There are three cases:
ZoneOffsetInfo.isTransition()
to handle the gap or overlap.dateTime
- the date-time to find the offset information for, not nullpublic abstract ZoneOffset getStandardOffset(InstantProvider instantProvider)
This provides access to historic information on how the standard offset has changed over time. The standard offset is the offset before any daylight savings time is applied. This is typically the offset applicable during winter.
instantProvider
- the instant to find the offset information for, not nullpublic Period getDaylightSavings(InstantProvider instantProvider)
This provides access to historic information on how the amount of daylight savings has changed over time. This is the difference between the standard offset and the actual offset. It is expressed in hours, minutes and seconds. Typically the amount is zero during winter and one hour during summer.
instantProvider
- the instant to find the offset information for, not nullpublic boolean isDaylightSavings(InstantProvider instant)
This provides access to historic information on how the standard offset has changed over time. The standard offset is the offset before any daylight savings time is applied. This is typically the offset applicable during winter.
instant
- the instant to find the offset information for, not nullpublic abstract ZoneOffsetTransition nextTransition(InstantProvider instantProvider)
This returns details of the next transition after the specified instant.
Some providers of rules may not be able to return this information, thus the method is defined to throw UnsupportedOperationException. The supplied rules implementations do supply this information and don't throw the exception
instantProvider
- the instant to get the next transition after, not nullUnsupportedOperationException
- if the implementation cannot return this information -
the default 'TZDB' can return this informationpublic abstract ZoneOffsetTransition previousTransition(InstantProvider instantProvider)
This returns details of the previous transition after the specified instant.
Some providers of rules may not be able to return this information, thus the method is defined to throw UnsupportedOperationException. The supplied rules implementations do supply this information and don't throw the exception
instantProvider
- the instant to get the previous transition after, not nullUnsupportedOperationException
- if the implementation cannot return this information -
the default 'TZDB' can return this informationpublic abstract List<ZoneOffsetTransition> getTransitions()
The complete set of transitions for this rules instance is defined by this method
and getTransitionRules()
. This method returns those transitions that have
been fully defined. These are typically historical, but may be in the future.
The list will be empty for fixed offset rules.
Some providers of rules cannot return this information, thus this method is defined to throw UnsupportedOperationException. The supplied 'TZDB' implementation can supply this information thus does not throw the exception.
UnsupportedOperationException
- if the implementation cannot return this information -
the default 'TZDB' can return this informationpublic abstract List<ZoneOffsetTransitionRule> getTransitionRules()
The complete set of transitions for this rules instance is defined by this method
and getTransitions()
. This method returns instances of ZoneOffsetTransitionRule
that define an algorithm for when transitions will occur.
The list will be empty for fixed offset rules.
For any given ZoneRules
, this list contains the transition rules for years
beyond those years that have been fully defined. These rules typically refer to future
daylight savings time rule changes.
If the zone defines daylight savings into the future, then the list will normally be of size two and hold information about entering and exiting daylight savings. If the zone does not have daylight savings, or information about future changes is uncertain, then the list will be empty.
Some providers of rules cannot return this information, thus this method is defined to throw UnsupportedOperationException. The supplied 'TZDB' implementation can supply this information thus does not throw the exception.
UnsupportedOperationException
- if the implementation cannot return this information -
the default 'TZDB' can return this informationpublic boolean isValidDateTime(OffsetDateTime dateTime)
To be valid, the local date-time must not be in a gap and the offset must match the valid offsets.
dateTime
- the date-time to check, not nullpublic abstract boolean equals(Object otherRules)
Two rule sets are equal if they will always result in the same output for any given input instant or date-time. Rules from two different groups may return false even if they are in fact the same.
This definition should result in implementations comparing their entire state.
Copyright © 2014. All rights reserved.