ZoneRules

The rules defining how the zone offset varies for a single time-zone. !(p) The rules model all the historic and future transitions for a time-zone. {@link ZoneOffsetTransition} is used for known transitions, typically historic. {@link ZoneOffsetTransitionRule} is used for future transitions that are based on the result of an algorithm. !(p) The rules are loaded via {@link ZoneRulesProvider} using a {@link ZoneId}. The same rules may be shared internally between multiple zone IDs. !(p) Serializing an instance of {@code ZoneRules} will store the entire set of rules. It does not store the zone ID as it is not part of the state of this object. !(p) A rule implementation may or may not store full information about historic and future transitions, and the information stored is only as accurate as that supplied to the implementation by the rules provider. Applications should treat the data provided as representing the best information available to the implementation of this rule.

@implSpec This class is immutable and thread-safe.

Constructors

this
this(ZoneOffset baseStandardOffset, ZoneOffset baseWallOffset, List!(ZoneOffsetTransition) standardOffsetTransitionList, List!(ZoneOffsetTransition) transitionList, List!(ZoneOffsetTransitionRule) lastRules)

Creates an instance.

Members

Functions

getOffset
ZoneOffset getOffset(Instant instant)

Gets the offset applicable at the specified instant _in these rules. !(p) The mapping from an instant to an offset is simple, there is only one valid offset for each instant. This method returns that offset.

getOffset
ZoneOffset getOffset(LocalDateTime localDateTime)

Gets a suitable offset for the specified local date-time _in these rules. !(p) The mapping from a local date-time to an offset is not straightforward. There are three cases: !(ul) !(li)Normal, with one valid offset. For the vast majority of the year, the normal case applies, where there is a single valid offset for the local date-time.</li> !(li)Gap, with zero valid offsets. This is when clocks jump forward typically due to the spring daylight savings change from "winter" to "summer". In a gap there are local date-time values with no valid offset.</li> !(li)Overlap, with two valid offsets. This is when clocks are set back typically due to the autumn daylight savings change from "summer" to "winter". In an overlap there are local date-time values with two valid offsets.</li> </ul> Thus, for any given local date-time there can be zero, one or two valid offsets. This method returns the single offset _in the Normal case, and _in the Gap or Overlap case it returns the offset before the transition. !(p) Since, _in the case of Gap and Overlap, the offset returned is a "best" value, rather than the "correct" value, it should be treated with care. Applications that care about the correct offset should use a combination of this method, {@link #getValidOffsets(LocalDateTime)} and {@link #getTransition(LocalDateTime)}.

getStandardOffset
ZoneOffset getStandardOffset(Instant instant)

Gets the standard offset for the specified instant _in this zone. !(p) This provides access to historic information on how the standard offset has changed over time. The standard offset is the offset before any daylight saving time is applied. This is typically the offset applicable during winter.

getTransition
ZoneOffsetTransition getTransition(LocalDateTime localDateTime)

Gets the offset transition applicable at the specified local date-time _in these rules. !(p) The mapping from a local date-time to an offset is not straightforward. There are three cases: !(ul) !(li)Normal, with one valid offset. For the vast majority of the year, the normal case applies, where there is a single valid offset for the local date-time.</li> !(li)Gap, with zero valid offsets. This is when clocks jump forward typically due to the spring daylight savings change from "winter" to "summer". In a gap there are local date-time values with no valid offset.</li> !(li)Overlap, with two valid offsets. This is when clocks are set back typically due to the autumn daylight savings change from "summer" to "winter". In an overlap there are local date-time values with two valid offsets.</li> </ul> A transition is used to model the cases of a Gap or Overlap. The Normal case will return null. !(p) There are various ways to handle the conversion from a {@code LocalDateTime}. One technique, using this method, would be: !(pre) ZoneOffsetTransition trans = rules.getTransition(localDT); if (trans !is null) { // Gap or Overlap: determine what to do from transition } else { // Normal case: only one valid offset zoneOffset = rule.getOffset(localDT); } </pre>

getTransitionRules
List!(ZoneOffsetTransitionRule) getTransitionRules()

Gets the list of transition rules for years beyond those defined _in the transition list. !(p) The complete set of transitions for this rules instance is defined by this method and {@link #getTransitions()}. This method returns instances of {@link ZoneOffsetTransitionRule} that define an algorithm for when transitions will occur. !(p) For any given {@code ZoneRules}, this list contains the transition rules for years beyond those years that have been fully defined. These rules typically refer to future daylight saving time rule changes. !(p) 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. !(p) The list will be empty for fixed offset rules and for any time-zone where there is no daylight saving time. The list will also be empty if the transition rules are unknown.

getTransitions
List!(ZoneOffsetTransition) getTransitions()

Gets the complete list of fully defined transitions. !(p) The complete set of transitions for this rules instance is defined by this method and {@link #getTransitionRules()}. This method returns those transitions that have been fully defined. These are typically historical, but may be _in the future. !(p) The list will be empty for fixed offset rules and for any time-zone where there has only ever been a single offset. The list will also be empty if the transition rules are unknown.

getValidOffsets
List!(ZoneOffset) getValidOffsets(LocalDateTime localDateTime)

Gets the offset applicable at the specified local date-time _in these rules. !(p) The mapping from a local date-time to an offset is not straightforward. There are three cases: !(ul) !(li)Normal, with one valid offset. For the vast majority of the year, the normal case applies, where there is a single valid offset for the local date-time.</li> !(li)Gap, with zero valid offsets. This is when clocks jump forward typically due to the spring daylight savings change from "winter" to "summer". In a gap there are local date-time values with no valid offset.</li> !(li)Overlap, with two valid offsets. This is when clocks are set back typically due to the autumn daylight savings change from "summer" to "winter". In an overlap there are local date-time values with two valid offsets.</li> </ul> Thus, for any given local date-time there can be zero, one or two valid offsets. This method returns that list of valid offsets, which is a list of size 0, 1 or 2. In the case where there are two offsets, the earlier offset is returned at index 0 and the later offset at index 1. !(p) There are various ways to handle the conversion from a {@code LocalDateTime}. One technique, using this method, would be: !(pre) List&lt;ZoneOffset&gt; validOffsets = rules.getOffset(localDT); if (validOffsets.size() == 1) { // Normal case: only one valid offset zoneOffset = validOffsets.get(0); } else { // Gap or Overlap: determine what to do from transition (which will be non-null) ZoneOffsetTransition trans = rules.getTransition(localDT); } </pre> !(p) In theory, it is possible for there to be more than two valid offsets. This would happen if clocks to be put back more than once _in quick succession. This has never happened _in the history of time-zones and thus has no special handling. However, if it were to happen, then the list would return more than 2 entries.

isDaylightSavings
bool isDaylightSavings(Instant instant)

Checks if the specified instant is _in daylight savings. !(p) This checks if the standard offset and the actual offset are the same for the specified instant. If they are not, it is assumed that daylight savings is _in operation. !(p) This default implementation compares the {@link #getOffset(hunt.time.Instant) actual} and {@link #getStandardOffset(hunt.time.Instant) standard} offsets.

isFixedOffset
bool isFixedOffset()

Checks of the zone rules are fixed, such that the offset never varies.

isValidOffset
bool isValidOffset(LocalDateTime localDateTime, ZoneOffset offset)

Checks if the offset date-time is valid for these rules. !(p) To be valid, the local date-time must not be _in a gap and the offset must match one of the valid offsets. !(p) This default implementation checks if {@link #getValidOffsets(hunt.time.LocalDateTime)} contains the specified offset.

nextTransition
ZoneOffsetTransition nextTransition(Instant instant)

Gets the next transition after the specified instant. !(p) This returns details of the next transition after the specified instant. For example, if the instant represents a point where "Summer" daylight savings time applies, then the method will return the transition to the next "Winter" time.

opEquals
bool opEquals(Object otherRules)

Checks if this set of rules equals another. !(p) Two rule sets are equal if they will always result _in the same output for any given input instant or local date-time. Rules from two different groups may return false even if they are _in fact the same. !(p) This definition should result _in implementations comparing their entire state.

previousTransition
ZoneOffsetTransition previousTransition(Instant instant)

Gets the previous transition before the specified instant. !(p) This returns details of the previous transition before the specified instant. For example, if the instant represents a point where "summer" daylight saving time applies, then the method will return the transition from the previous "winter" time.

toHash
size_t toHash()

Returns a suitable hash code given the definition of {@code #equals}.

toString
string toString()

Returns a string describing this object.

writeExternal
void writeExternal(DataOutput _out)

Writes the state to the stream.

Static functions

of
ZoneRules of(ZoneOffset baseStandardOffset, ZoneOffset baseWallOffset, List!(ZoneOffsetTransition) standardOffsetTransitionList, List!(ZoneOffsetTransition) transitionList, List!(ZoneOffsetTransitionRule) lastRules)

Obtains an instance of a ZoneRules.

of
ZoneRules of(ZoneOffset offset)

Obtains an instance of ZoneRules that has fixed zone rules.

readExternal
ZoneRules readExternal(DataInput _in)

Reads the state from the stream.

Static variables

EMPTY_LASTRULES
ZoneOffsetTransitionRule[] EMPTY_LASTRULES;

The zero-length lastrules array.

EMPTY_LDT_ARRAY
LocalDateTime[] EMPTY_LDT_ARRAY;

The zero-length ldt array.

EMPTY_LONG_ARRAY
long[] EMPTY_LONG_ARRAY;

The zero-length long array.

Meta