Top Description Fields Constructors Methods
java.time.zone

public final Class ZoneRules

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.DataInput, .DataOutput, .IOException, .InvalidObjectException, .ObjectInputStream, .Serializable, java.time.Duration, .Instant, .LocalDateTime, .ZoneId, .ZoneOffset, .Year, java.util.ArrayList, .Arrays, .Collections, .List, .Objects, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap

The rules defining how the zone offset varies for a single time-zone.

The rules model all the historic and future transitions for a time-zone. ZoneOffsetTransition is used for known transitions, typically historic. ZoneOffsetTransitionRule is used for future transitions that are based on the result of an algorithm.

The rules are loaded via ZoneRulesProvider using a ZoneId. The same rules may be shared internally between multiple zone IDs.

Serializing an instance of 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.

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.

Implementation Specification

This class is immutable and thread-safe.

Since
1.8

Field Summary

Modifier and TypeField and Description
private static final long
DAYS_0000_TO_1970

The number of days from year zero to year 1970.

private static final int
DAYS_PER_CYCLE

The number of days in a 400 year cycle.

private static final ZoneOffsetTransitionRule[]
EMPTY_LASTRULES

The zero-length lastrules array.

private static final LocalDateTime[]
EMPTY_LDT_ARRAY

The zero-length ldt array.

private static final long[]
EMPTY_LONG_ARRAY

The zero-length long array.

private static final int
LAST_CACHED_YEAR

The last year to have its transitions cached.

private final ZoneOffsetTransitionRule[]
lastRules

The last rule.

private final transient ConcurrentMap<Integer, ZoneOffsetTransition[]>
lastRulesCache

The map of recent transitions.

private final long[]
savingsInstantTransitions

The transitions between instants (epoch seconds), sorted.

private final LocalDateTime[]
savingsLocalTransitions

The transitions between local date-times, sorted.

private static final long
serialVersionUID

Serialization version.

private final ZoneOffset[]
standardOffsets

The standard offsets.

private final long[]
standardTransitions

The transitions between standard offsets (epoch seconds), sorted.

private final ZoneOffset[]
wallOffsets

The wall offsets.

Constructor Summary

AccessConstructor and Description
pack-priv
ZoneRules(ZoneOffset
the standard offset to use before legal rules were set, not null
baseStandardOffset
,
ZoneOffset
the wall offset to use before legal rules were set, not null
baseWallOffset
,
List<ZoneOffsetTransition>
the list of changes to the standard offset, not null
standardOffsetTransitionList
,
List<ZoneOffsetTransition>
the list of transitions, not null
transitionList
,
List<ZoneOffsetTransitionRule>
the recurring last rules, size 16 or less, not null
lastRules
)

Creates an instance.

private
ZoneRules(long[]
the standard transitions, not null
standardTransitions
,
ZoneOffset[]
the standard offsets, not null
standardOffsets
,
long[]
the standard transitions, not null
savingsInstantTransitions
,
ZoneOffset[]
the wall offsets, not null
wallOffsets
,
ZoneOffsetTransitionRule[]
the recurring last rules, size 15 or less, not null
lastRules
)

Constructor.

private
ZoneRules(ZoneOffset
the offset this fixed zone rules is based on, not null
offset
)

Creates an instance of ZoneRules that has fixed zone rules.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this rules is the same as that specified
equals
(Object
the other rules, null returns false
otherRules
)

Overrides java.lang.Object.equals.

Checks if this set of rules equals another.
private Object

Returns:

the offset info, not null
findOffsetInfo
(LocalDateTime
the date-time, not null
dt
,
ZoneOffsetTransition
the transition, not null
trans
)

Finds the offset info for a local date-time and transition.

private ZoneOffsetTransition[]

Returns:

the transition array, not null
findTransitionArray
(int
the year, not null
year
)

Finds the appropriate transition array for the given year.

private int
findYear(long epochSecond, ZoneOffset offset)

public Duration

Returns:

the difference between the standard and actual offset, not null
getDaylightSavings
(Instant
the instant to find the daylight savings for, not null, but null may be ignored if the rules have a single offset for all instants
instant
)

Gets the amount of daylight savings in use for the specified instant in this zone.

public ZoneOffset

Returns:

the offset, not null
getOffset
(Instant
the instant to find the offset for, not null, but null may be ignored if the rules have a single offset for all instants
instant
)

Gets the offset applicable at the specified instant in these rules.

public ZoneOffset

Returns:

the best available offset for the local date-time, not null
getOffset
(LocalDateTime
the local date-time to query, not null, but null may be ignored if the rules have a single offset for all instants
localDateTime
)

Gets a suitable offset for the specified local date-time in these rules.

private Object
public ZoneOffset

Returns:

the standard offset, not null
getStandardOffset
(Instant
the instant to find the offset information for, not null, but null may be ignored if the rules have a single offset for all instants
instant
)

Gets the standard offset for the specified instant in this zone.

public ZoneOffsetTransition

Returns:

the offset transition, null if the local date-time is not in transition
getTransition
(LocalDateTime
the local date-time to query for offset transition, not null, but null may be ignored if the rules have a single offset for all instants
localDateTime
)

Gets the offset transition applicable at the specified local date-time in these rules.

public List<ZoneOffsetTransitionRule>

Returns:

an immutable list of transition rules, not null
getTransitionRules
()

Gets the list of transition rules for years beyond those defined in the transition list.

public List<ZoneOffsetTransition>

Returns:

an immutable list of fully defined transitions, not null
getTransitions
()

Gets the complete list of fully defined transitions.

public List<ZoneOffset>

Returns:

the list of valid offsets, may be immutable, not null
getValidOffsets
(LocalDateTime
the local date-time to query for valid offsets, not null, but null may be ignored if the rules have a single offset for all instants
localDateTime
)

Gets the offset applicable at the specified local date-time in these rules.

public int

Returns:

the hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code given the definition of #equals.
public boolean

Returns:

true if the specified instant is in daylight savings, false otherwise.
isDaylightSavings
(Instant
the instant to check the daylight savings for, not null, but null may be ignored if the rules have a single offset for all instants
instant
)

Checks if the specified instant is in daylight savings.

public boolean

Returns:

true if the time-zone is fixed and the offset never changes
isFixedOffset
()

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

public boolean

Returns:

true if the offset date-time is valid for these rules
isValidOffset
(LocalDateTime
the date-time to check, not null, but null may be ignored if the rules have a single offset for all instants
localDateTime
,
ZoneOffset
the offset to check, null returns false
offset
)

Checks if the offset date-time is valid for these rules.

public ZoneOffsetTransition

Returns:

the next transition after the specified instant, null if this is after the last transition
nextTransition
(Instant
the instant to get the next transition after, not null, but null may be ignored if the rules have a single offset for all instants
instant
)

Gets the next transition after the specified instant.

public static ZoneRules

Returns:

the zone rules, not null
of
(ZoneOffset
the standard offset to use before legal rules were set, not null
baseStandardOffset
,
ZoneOffset
the wall offset to use before legal rules were set, not null
baseWallOffset
,
List<ZoneOffsetTransition>
the list of changes to the standard offset, not null
standardOffsetTransitionList
,
List<ZoneOffsetTransition>
the list of transitions, not null
transitionList
,
List<ZoneOffsetTransitionRule>
the recurring last rules, size 16 or less, not null
lastRules
)

Obtains an instance of a ZoneRules.

public static ZoneRules

Returns:

the zone rules, not null
of
(ZoneOffset
the offset this fixed zone rules is based on, not null
offset
)

Obtains an instance of ZoneRules that has fixed zone rules.

public ZoneOffsetTransition

Returns:

the previous transition before the specified instant, null if this is before the first transition
previousTransition
(Instant
the instant to get the previous transition after, not null, but null may be ignored if the rules have a single offset for all instants
instant
)

Gets the previous transition before the specified instant.

pack-priv static ZoneRules

Returns:

the created object, not null
readExternal
(DataInput
the input stream, not null
in
)

Reads the state from the stream.

private void
readObject(ObjectInputStream
the stream to read
s
)

Defend against malicious streams.

public String

Returns:

a string for debugging, not null
toString
()

Overrides java.lang.Object.toString.

Returns a string describing this object.
pack-priv void
writeExternal(DataOutput
the output stream, not null
out
)

Writes the state to the stream.

private Object

Returns:

the replacing object, not null
writeReplace
()

Writes the object using a dedicated serialized form.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

DAYS_0000_TO_1970back to summary
private static final long DAYS_0000_TO_1970

The number of days from year zero to year 1970. There are five 400 year cycles from year zero to 2000. There are 7 leap years from 1970 to 2000.

DAYS_PER_CYCLEback to summary
private static final int DAYS_PER_CYCLE

The number of days in a 400 year cycle.

EMPTY_LASTRULESback to summary
private static final ZoneOffsetTransitionRule[] EMPTY_LASTRULES

The zero-length lastrules array.

EMPTY_LDT_ARRAYback to summary
private static final LocalDateTime[] EMPTY_LDT_ARRAY

The zero-length ldt array.

EMPTY_LONG_ARRAYback to summary
private static final long[] EMPTY_LONG_ARRAY

The zero-length long array.

LAST_CACHED_YEARback to summary
private static final int LAST_CACHED_YEAR

The last year to have its transitions cached.

lastRulesback to summary
private final ZoneOffsetTransitionRule[] lastRules

The last rule.

lastRulesCacheback to summary
private final transient ConcurrentMap<Integer, ZoneOffsetTransition[]> lastRulesCache

The map of recent transitions.

savingsInstantTransitionsback to summary
private final long[] savingsInstantTransitions

The transitions between instants (epoch seconds), sorted.

savingsLocalTransitionsback to summary
private final LocalDateTime[] savingsLocalTransitions

The transitions between local date-times, sorted. This is a paired array, where the first entry is the start of the transition and the second entry is the end of the transition.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

standardOffsetsback to summary
private final ZoneOffset[] standardOffsets

The standard offsets.

standardTransitionsback to summary
private final long[] standardTransitions

The transitions between standard offsets (epoch seconds), sorted.

wallOffsetsback to summary
private final ZoneOffset[] wallOffsets

The wall offsets.

Constructor Detail

ZoneRulesback to summary
pack-priv ZoneRules(ZoneOffset baseStandardOffset, ZoneOffset baseWallOffset, List<ZoneOffsetTransition> standardOffsetTransitionList, List<ZoneOffsetTransition> transitionList, List<ZoneOffsetTransitionRule> lastRules)

Creates an instance.

Parameters
baseStandardOffset:ZoneOffset

the standard offset to use before legal rules were set, not null

baseWallOffset:ZoneOffset

the wall offset to use before legal rules were set, not null

standardOffsetTransitionList:List<ZoneOffsetTransition>

the list of changes to the standard offset, not null

transitionList:List<ZoneOffsetTransition>

the list of transitions, not null

lastRules:List<ZoneOffsetTransitionRule>

the recurring last rules, size 16 or less, not null

ZoneRulesback to summary
private ZoneRules(long[] standardTransitions, ZoneOffset[] standardOffsets, long[] savingsInstantTransitions, ZoneOffset[] wallOffsets, ZoneOffsetTransitionRule[] lastRules)

Constructor.

Parameters
standardTransitions:long[]

the standard transitions, not null

standardOffsets:ZoneOffset[]

the standard offsets, not null

savingsInstantTransitions:long[]

the standard transitions, not null

wallOffsets:ZoneOffset[]

the wall offsets, not null

lastRules:ZoneOffsetTransitionRule[]

the recurring last rules, size 15 or less, not null

ZoneRulesback to summary
private ZoneRules(ZoneOffset offset)

Creates an instance of ZoneRules that has fixed zone rules.

Parameters
offset:ZoneOffset

the offset this fixed zone rules is based on, not null

See Also
isFixedOffset()

Method Detail

equalsback to summary
public boolean equals(Object otherRules)

Overrides java.lang.Object.equals.

Checks if this set of rules equals another.

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.

This definition should result in implementations comparing their entire state.

Parameters
otherRules:Object

the other rules, null returns false

Returns:boolean

true if this rules is the same as that specified

Annotations
@Override
findOffsetInfoback to summary
private Object findOffsetInfo(LocalDateTime dt, ZoneOffsetTransition trans)

Finds the offset info for a local date-time and transition.

Parameters
dt:LocalDateTime

the date-time, not null

trans:ZoneOffsetTransition

the transition, not null

Returns:Object

the offset info, not null

findTransitionArrayback to summary
private ZoneOffsetTransition[] findTransitionArray(int year)

Finds the appropriate transition array for the given year.

Parameters
year:int

the year, not null

Returns:ZoneOffsetTransition[]

the transition array, not null

findYearback to summary
private int findYear(long epochSecond, ZoneOffset offset)
getDaylightSavingsback to summary
public Duration getDaylightSavings(Instant instant)

Gets the amount of daylight savings in use for the specified instant in this zone.

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. Typically the amount is zero during winter and one hour during summer. Time-zones are second-based, so the nanosecond part of the duration will be zero.

This default implementation calculates the duration from the actual and standard offsets.

Parameters
instant:Instant

the instant to find the daylight savings for, not null, but null may be ignored if the rules have a single offset for all instants

Returns:Duration

the difference between the standard and actual offset, not null

getOffsetback to summary
public ZoneOffset getOffset(Instant instant)

Gets the offset applicable at the specified instant in these rules.

The mapping from an instant to an offset is simple, there is only one valid offset for each instant. This method returns that offset.

Parameters
instant:Instant

the instant to find the offset for, not null, but null may be ignored if the rules have a single offset for all instants

Returns:ZoneOffset

the offset, not null

getOffsetback to summary
public ZoneOffset getOffset(LocalDateTime localDateTime)

Gets a suitable offset for the specified local date-time in these rules.

The mapping from a local date-time to an offset is not straightforward. There are three cases:

  • 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.
  • 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.
  • 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.
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.

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, getValidOffsets(LocalDateTime) and getTransition(LocalDateTime).

Parameters
localDateTime:LocalDateTime

the local date-time to query, not null, but null may be ignored if the rules have a single offset for all instants

Returns:ZoneOffset

the best available offset for the local date-time, not null

getOffsetInfoback to summary
private Object getOffsetInfo(LocalDateTime dt)
getStandardOffsetback to summary
public ZoneOffset getStandardOffset(Instant instant)

Gets the standard offset for the specified instant in this zone.

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.

Parameters
instant:Instant

the instant to find the offset information for, not null, but null may be ignored if the rules have a single offset for all instants

Returns:ZoneOffset

the standard offset, not null

getTransitionback to summary
public ZoneOffsetTransition getTransition(LocalDateTime localDateTime)

Gets the offset transition applicable at the specified local date-time in these rules.

The mapping from a local date-time to an offset is not straightforward. There are three cases:

  • 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.
  • 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.
  • 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.
A transition is used to model the cases of a Gap or Overlap. The Normal case will return null.

There are various ways to handle the conversion from a LocalDateTime. One technique, using this method, would be:

 ZoneOffsetTransition trans = rules.getTransition(localDT);
 if (trans != null) {
   // Gap or Overlap: determine what to do from transition
 } else {
   // Normal case: only one valid offset
   zoneOffset = rule.getOffset(localDT);
 }
Parameters
localDateTime:LocalDateTime

the local date-time to query for offset transition, not null, but null may be ignored if the rules have a single offset for all instants

Returns:ZoneOffsetTransition

the offset transition, null if the local date-time is not in transition

getTransitionRulesback to summary
public List<ZoneOffsetTransitionRule> getTransitionRules()

Gets the list of transition rules for years beyond those defined in the transition list.

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.

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 saving 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.

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.

Returns:List<ZoneOffsetTransitionRule>

an immutable list of transition rules, not null

getTransitionsback to summary
public List<ZoneOffsetTransition> getTransitions()

Gets the complete list of fully defined transitions.

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 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.

Returns:List<ZoneOffsetTransition>

an immutable list of fully defined transitions, not null

getValidOffsetsback to summary
public List<ZoneOffset> getValidOffsets(LocalDateTime localDateTime)

Gets the offset applicable at the specified local date-time in these rules.

The mapping from a local date-time to an offset is not straightforward. There are three cases:

  • 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.
  • 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.
  • 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.
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.

There are various ways to handle the conversion from a LocalDateTime. One technique, using this method, would be:

 List<ZoneOffset> validOffsets = rules.getValidOffsets(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);
 }

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.

Parameters
localDateTime:LocalDateTime

the local date-time to query for valid offsets, not null, but null may be ignored if the rules have a single offset for all instants

Returns:List<ZoneOffset>

the list of valid offsets, may be immutable, not null

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

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

Returns:int

the hash code

Annotations
@Override
isDaylightSavingsback to summary
public boolean isDaylightSavings(Instant instant)

Checks if the specified instant is in daylight savings.

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.

This default implementation compares the actual and standard offsets.

Parameters
instant:Instant

the instant to check the daylight savings for, not null, but null may be ignored if the rules have a single offset for all instants

Returns:boolean

true if the specified instant is in daylight savings, false otherwise.

isFixedOffsetback to summary
public boolean isFixedOffset()

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

Returns:boolean

true if the time-zone is fixed and the offset never changes

isValidOffsetback to summary
public boolean isValidOffset(LocalDateTime localDateTime, ZoneOffset offset)

Checks if the offset date-time is valid for these rules.

To be valid, the local date-time must not be in a gap and the offset must match one of the valid offsets.

This default implementation checks if getValidOffsets(java.time.LocalDateTime) contains the specified offset.

Parameters
localDateTime:LocalDateTime

the date-time to check, not null, but null may be ignored if the rules have a single offset for all instants

offset:ZoneOffset

the offset to check, null returns false

Returns:boolean

true if the offset date-time is valid for these rules

nextTransitionback to summary
public ZoneOffsetTransition nextTransition(Instant instant)

Gets the next transition after the specified instant.

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.

Parameters
instant:Instant

the instant to get the next transition after, not null, but null may be ignored if the rules have a single offset for all instants

Returns:ZoneOffsetTransition

the next transition after the specified instant, null if this is after the last transition

ofback to summary
public static ZoneRules of(ZoneOffset baseStandardOffset, ZoneOffset baseWallOffset, List<ZoneOffsetTransition> standardOffsetTransitionList, List<ZoneOffsetTransition> transitionList, List<ZoneOffsetTransitionRule> lastRules)

Obtains an instance of a ZoneRules.

Parameters
baseStandardOffset:ZoneOffset

the standard offset to use before legal rules were set, not null

baseWallOffset:ZoneOffset

the wall offset to use before legal rules were set, not null

standardOffsetTransitionList:List<ZoneOffsetTransition>

the list of changes to the standard offset, not null

transitionList:List<ZoneOffsetTransition>

the list of transitions, not null

lastRules:List<ZoneOffsetTransitionRule>

the recurring last rules, size 16 or less, not null

Returns:ZoneRules

the zone rules, not null

ofback to summary
public static ZoneRules of(ZoneOffset offset)

Obtains an instance of ZoneRules that has fixed zone rules.

Parameters
offset:ZoneOffset

the offset this fixed zone rules is based on, not null

Returns:ZoneRules

the zone rules, not null

See Also
isFixedOffset()
previousTransitionback to summary
public ZoneOffsetTransition previousTransition(Instant instant)

Gets the previous transition before the specified instant.

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.

Parameters
instant:Instant

the instant to get the previous transition after, not null, but null may be ignored if the rules have a single offset for all instants

Returns:ZoneOffsetTransition

the previous transition before the specified instant, null if this is before the first transition

readExternalback to summary
pack-priv static ZoneRules readExternal(DataInput in) throws IOException, ClassNotFoundException

Reads the state from the stream. The 1,024 limit to the lengths of stdTrans and savSize is intended to be the size well enough to accommodate the max number of transitions in current tzdb data (203 for Asia/Tehran).

Parameters
in:DataInput

the input stream, not null

Returns:ZoneRules

the created object, not null

Exceptions
IOException:
if an error occurs
readObjectback to summary
private void readObject(ObjectInputStream s) throws InvalidObjectException

Defend against malicious streams.

Parameters
s:ObjectInputStream

the stream to read

Exceptions
InvalidObjectException:
always
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string describing this object.

Returns:String

a string for debugging, not null

Annotations
@Override
writeExternalback to summary
pack-priv void writeExternal(DataOutput out) throws IOException

Writes the state to the stream.

Parameters
out:DataOutput

the output stream, not null

Exceptions
IOException:
if an error occurs
writeReplaceback to summary
private Object writeReplace()

Writes the object using a dedicated serialized form.

Returns:Object

the replacing object, not null

Serial data
out.writeByte(1);  // identifies a ZoneRules
   out.writeInt(standardTransitions.length);
   for (long trans : standardTransitions) {
       Ser.writeEpochSec(trans, out);
   }
   for (ZoneOffset offset : standardOffsets) {
       Ser.writeOffset(offset, out);
   }
   out.writeInt(savingsInstantTransitions.length);
   for (long trans : savingsInstantTransitions) {
       Ser.writeEpochSec(trans, out);
   }
   for (ZoneOffset offset : wallOffsets) {
       Ser.writeOffset(offset, out);
   }
   out.writeByte(lastRules.length);
   for (ZoneOffsetTransitionRule rule : lastRules) {
       rule.writeExternal(out);
   }
 
 

Epoch second values used for offsets are encoded in a variable length form to make the common cases put fewer bytes in the stream.

static void writeEpochSec(long epochSec, DataOutput out) throws IOException {
     if (epochSec >= -4575744000L && epochSec < 10413792000L && epochSec % 900 == 0) {  // quarter hours between 1825 and 2300
         int store = (int) ((epochSec + 4575744000L) / 900);
         out.writeByte((store >>> 16) & 255);
         out.writeByte((store >>> 8) & 255);
         out.writeByte(store & 255);
      } else {
          out.writeByte(255);
          out.writeLong(epochSec);
      }
  }
 
 

ZoneOffset values are encoded in a variable length form so the common cases put fewer bytes in the stream.

static void writeOffset(ZoneOffset offset, DataOutput out) throws IOException {
     final int offsetSecs = offset.getTotalSeconds();
     int offsetByte = offsetSecs % 900 == 0 ? offsetSecs / 900 : 127;  // compress to -72 to +72
     out.writeByte(offsetByte);
     if (offsetByte == 127) {
         out.writeInt(offsetSecs);
     }
 }