Top Description Fields Constructors Methods
java.time.zone

public final Class ZoneOffsetTransition

extends Object
implements Comparable<ZoneOffsetTransition>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable
Imports
java.io.DataInput, .DataOutput, .IOException, .InvalidObjectException, .ObjectInputStream, .Serializable, java.time.Duration, .Instant, .LocalDateTime, .ZoneOffset, java.util.Arrays, .Collections, .List, .Objects

A transition between two offsets caused by a discontinuity in the local time-line.

A transition between two offsets is normally the result of a daylight savings cutover. The discontinuity is normally a gap in spring and an overlap in autumn. ZoneOffsetTransition models the transition between the two offsets.

Gaps occur where there are local date-times that simply do not exist. An example would be when the offset changes from +03:00 to +04:00. This might be described as 'the clocks will move forward one hour tonight at 1am'.

Overlaps occur where there are local date-times that exist twice. An example would be when the offset changes from +04:00 to +03:00. This might be described as 'the clocks will move back one hour tonight at 2am'.

Implementation Specification

This class is immutable and thread-safe.

Since
1.8

Field Summary

Modifier and TypeField and Description
private final long
epochSecond

The transition epoch-second.

private final ZoneOffset
offsetAfter

The offset after transition.

private final ZoneOffset
offsetBefore

The offset before transition.

private static final long
serialVersionUID

Serialization version.

private final LocalDateTime
transition

The local transition date-time at the transition.

Constructor Summary

AccessConstructor and Description
pack-priv
ZoneOffsetTransition(LocalDateTime
the transition date-time with the offset before the transition, not null
transition
,
ZoneOffset
the offset before the transition, not null
offsetBefore
,
ZoneOffset
the offset at and after the transition, not null
offsetAfter
)

Creates an instance defining a transition between two offsets.

pack-priv
ZoneOffsetTransition(long
the transition epoch-second
epochSecond
,
ZoneOffset
the offset before the transition, not null
offsetBefore
,
ZoneOffset
the offset at and after the transition, not null
offsetAfter
)

Creates an instance from epoch-second and offsets.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the comparator value, that is the comparison of this transition instant with otherTransition instant
compareTo
(ZoneOffsetTransition
the transition to compare to, not null
otherTransition
)

Implements java.lang.Comparable.compareTo.

Compares this transition to another based on the transition instant.

public boolean

Returns:

true if equal
equals
(Object
the other object to compare to, null returns false
other
)

Overrides java.lang.Object.equals.

Checks if this object equals another.

public LocalDateTime

Returns:

the transition date-time expressed with the after offset, not null
getDateTimeAfter
()

Gets the local transition date-time, as would be expressed with the 'after' offset.

public LocalDateTime

Returns:

the transition date-time expressed with the before offset, not null
getDateTimeBefore
()

Gets the local transition date-time, as would be expressed with the 'before' offset.

public Duration

Returns:

the duration of the transition, positive for gaps, negative for overlaps
getDuration
()

Gets the duration of the transition.

private int

Returns:

the duration in seconds
getDurationSeconds
()

Gets the duration of the transition in seconds.

public Instant

Returns:

the transition instant, not null
getInstant
()

Gets the transition instant.

public ZoneOffset

Returns:

the offset after the transition, not null
getOffsetAfter
()

Gets the offset after the transition.

public ZoneOffset

Returns:

the offset before the transition, not null
getOffsetBefore
()

Gets the offset before the transition.

pack-priv List<ZoneOffset>

Returns:

the list of valid offsets
getValidOffsets
()

Gets the valid offsets during this transition.

public int

Returns:

the hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code.

public boolean

Returns:

true if this transition is a gap, false if it is an overlap
isGap
()

Does this transition represent a gap in the local time-line.

public boolean

Returns:

true if this transition is an overlap, false if it is a gap
isOverlap
()

Does this transition represent an overlap in the local time-line.

public boolean

Returns:

true if the offset is valid during the transition
isValidOffset
(ZoneOffset
the offset to check, null returns false
offset
)

Checks if the specified offset is valid during this transition.

public static ZoneOffsetTransition

Returns:

the transition, not null
of
(LocalDateTime
the transition date-time at the transition, which never actually occurs, expressed local to the before offset, not null
transition
,
ZoneOffset
the offset before the transition, not null
offsetBefore
,
ZoneOffset
the offset at and after the transition, not null
offsetAfter
)

Obtains an instance defining a transition between two offsets.

pack-priv static ZoneOffsetTransition

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 long

Returns:

the transition epoch second
toEpochSecond
()

Gets the transition instant as an epoch second.

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

epochSecondback to summary
private final long epochSecond

The transition epoch-second.

offsetAfterback to summary
private final ZoneOffset offsetAfter

The offset after transition.

offsetBeforeback to summary
private final ZoneOffset offsetBefore

The offset before transition.

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

transitionback to summary
private final LocalDateTime transition

The local transition date-time at the transition.

Constructor Detail

ZoneOffsetTransitionback to summary
pack-priv ZoneOffsetTransition(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter)

Creates an instance defining a transition between two offsets.

Parameters
transition:LocalDateTime

the transition date-time with the offset before the transition, not null

offsetBefore:ZoneOffset

the offset before the transition, not null

offsetAfter:ZoneOffset

the offset at and after the transition, not null

ZoneOffsetTransitionback to summary
pack-priv ZoneOffsetTransition(long epochSecond, ZoneOffset offsetBefore, ZoneOffset offsetAfter)

Creates an instance from epoch-second and offsets.

Parameters
epochSecond:long

the transition epoch-second

offsetBefore:ZoneOffset

the offset before the transition, not null

offsetAfter:ZoneOffset

the offset at and after the transition, not null

Method Detail

compareToback to summary
public int compareTo(ZoneOffsetTransition otherTransition)

Implements java.lang.Comparable.compareTo.

Compares this transition to another based on the transition instant.

This compares the instants of each transition. The offsets are ignored, making this order inconsistent with equals.

Parameters
otherTransition:ZoneOffsetTransition

the transition to compare to, not null

Returns:int

the comparator value, that is the comparison of this transition instant with otherTransition instant

Annotations
@Override
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Checks if this object equals another.

The entire state of the object is compared.

Parameters
other:Object

the other object to compare to, null returns false

Returns:boolean

true if equal

Annotations
@Override
getDateTimeAfterback to summary
public LocalDateTime getDateTimeAfter()

Gets the local transition date-time, as would be expressed with the 'after' offset.

This is the first date-time after the discontinuity, when the new offset applies.

The combination of the 'before' date-time and offset represents the same instant as the 'after' date-time and offset.

Returns:LocalDateTime

the transition date-time expressed with the after offset, not null

getDateTimeBeforeback to summary
public LocalDateTime getDateTimeBefore()

Gets the local transition date-time, as would be expressed with the 'before' offset.

This is the date-time where the discontinuity begins expressed with the 'before' offset. At this instant, the 'after' offset is actually used, therefore the combination of this date-time and the 'before' offset will never occur.

The combination of the 'before' date-time and offset represents the same instant as the 'after' date-time and offset.

Returns:LocalDateTime

the transition date-time expressed with the before offset, not null

getDurationback to summary
public Duration getDuration()

Gets the duration of the transition.

In most cases, the transition duration is one hour, however this is not always the case. The duration will be positive for a gap and negative for an overlap. Time-zones are second-based, so the nanosecond part of the duration will be zero.

Returns:Duration

the duration of the transition, positive for gaps, negative for overlaps

getDurationSecondsback to summary
private int getDurationSeconds()

Gets the duration of the transition in seconds.

Returns:int

the duration in seconds

getInstantback to summary
public Instant getInstant()

Gets the transition instant.

This is the instant of the discontinuity, which is defined as the first instant that the 'after' offset applies.

The methods getInstant(), getDateTimeBefore() and getDateTimeAfter() all represent the same instant.

Returns:Instant

the transition instant, not null

getOffsetAfterback to summary
public ZoneOffset getOffsetAfter()

Gets the offset after the transition.

This is the offset in use on and after the instant of the transition.

Returns:ZoneOffset

the offset after the transition, not null

getOffsetBeforeback to summary
public ZoneOffset getOffsetBefore()

Gets the offset before the transition.

This is the offset in use before the instant of the transition.

Returns:ZoneOffset

the offset before the transition, not null

getValidOffsetsback to summary
pack-priv List<ZoneOffset> getValidOffsets()

Gets the valid offsets during this transition.

A gap will return an empty list, while an overlap will return both offsets.

Returns:List<ZoneOffset>

the list of valid offsets

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a suitable hash code.

Returns:int

the hash code

Annotations
@Override
isGapback to summary
public boolean isGap()

Does this transition represent a gap in the local time-line.

Gaps occur where there are local date-times that simply do not exist. An example would be when the offset changes from +01:00 to +02:00. This might be described as 'the clocks will move forward one hour tonight at 1am'.

Returns:boolean

true if this transition is a gap, false if it is an overlap

isOverlapback to summary
public boolean isOverlap()

Does this transition represent an overlap in the local time-line.

Overlaps occur where there are local date-times that exist twice. An example would be when the offset changes from +02:00 to +01:00. This might be described as 'the clocks will move back one hour tonight at 2am'.

Returns:boolean

true if this transition is an overlap, false if it is a gap

isValidOffsetback to summary
public boolean isValidOffset(ZoneOffset offset)

Checks if the specified offset is valid during this transition.

This checks to see if the given offset will be valid at some point in the transition. A gap will always return false. An overlap will return true if the offset is either the before or after offset.

Parameters
offset:ZoneOffset

the offset to check, null returns false

Returns:boolean

true if the offset is valid during the transition

ofback to summary
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter)

Obtains an instance defining a transition between two offsets.

Applications should normally obtain an instance from ZoneRules. This factory is only intended for use when creating ZoneRules.

Parameters
transition:LocalDateTime

the transition date-time at the transition, which never actually occurs, expressed local to the before offset, not null

offsetBefore:ZoneOffset

the offset before the transition, not null

offsetAfter:ZoneOffset

the offset at and after the transition, not null

Returns:ZoneOffsetTransition

the transition, not null

Exceptions
IllegalArgumentException:
if offsetBefore and offsetAfter are equal, or transition.getNano() returns non-zero value
readExternalback to summary
pack-priv static ZoneOffsetTransition readExternal(DataInput in) throws IOException

Reads the state from the stream.

Parameters
in:DataInput

the input stream, not null

Returns:ZoneOffsetTransition

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
toEpochSecondback to summary
public long toEpochSecond()

Gets the transition instant as an epoch second.

Returns:long

the transition epoch second

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
Refer to the serialized form of ZoneRules.writeReplace for the encoding of epoch seconds and offsets.
out.writeByte(2);                // identifies a ZoneOffsetTransition
  out.writeEpochSec(toEpochSecond);
  out.writeOffset(offsetBefore);
  out.writeOffset(offsetAfter);