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.
Modifier and Type | Field 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. |
Access | Constructor 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. |
Modifier and Type | Method and Description |
---|---|
public int | Returns: the comparator value, that is the comparison of this transition instant withotherTransition instantthe transition to compare to, not null otherTransition)Implements java. Compares this transition to another based on the transition instant. |
public boolean | Returns: true if equalthe other object to compare to, null returns false other)Overrides java. Checks if this object equals another. |
public LocalDateTime | Returns: the transition date-time expressed with the after offset, not nullGets 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 nullGets 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 overlapsGets the duration of the transition. |
private int | |
public Instant | |
public ZoneOffset | Returns: the offset after the transition, not nullGets the offset after the transition. |
public ZoneOffset | Returns: the offset before the transition, not nullGets the offset before the transition. |
pack-priv List | |
public int | |
public boolean | Returns: true if this transition is a gap, false if it is an overlapDoes 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 gapDoes this transition represent an overlap in the local time-line. |
public boolean | Returns: true if the offset is valid during the transitionthe offset to check, null returns false offset)Checks if the specified offset is valid during this transition. |
public static ZoneOffsetTransition | Returns: the transition, not nullthe 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 nullthe input stream, not null in)Reads the state from the stream. |
private void | |
public long | |
public String | Returns: a string for debugging, not nullOverrides java. Returns a string describing this object. |
pack-priv void | |
private Object | Returns: the replacing object, not nullWrites the object using a dedicated serialized form. |
epochSecond | back to summary |
---|---|
private final long epochSecond The transition epoch-second. |
offsetAfter | back to summary |
---|---|
private final ZoneOffset offsetAfter The offset after transition. |
offsetBefore | back to summary |
---|---|
private final ZoneOffset offsetBefore The offset before transition. |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Serialization version. |
transition | back to summary |
---|---|
private final LocalDateTime transition The local transition date-time at the transition. |
ZoneOffsetTransition | back to summary |
---|---|
pack-priv ZoneOffsetTransition(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) Creates an instance defining a transition between two offsets.
|
ZoneOffsetTransition | back to summary |
---|---|
pack-priv ZoneOffsetTransition(long epochSecond, ZoneOffset offsetBefore, ZoneOffset offsetAfter) Creates an instance from epoch-second and offsets.
|
compareTo | back to summary |
---|---|
public int compareTo(ZoneOffsetTransition otherTransition) Implements java. 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.
|
equals | back to summary |
---|---|
public boolean equals(Object other) Overrides java. Checks if this object equals another. The entire state of the object is compared. |
getDateTimeAfter | back 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.
|
getDateTimeBefore | back 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.
|
getDuration | back 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.
|
getDurationSeconds | back to summary |
---|---|
private int getDurationSeconds() Gets the duration of the transition in seconds.
|
getInstant | back 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
|
getOffsetAfter | back 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.
|
getOffsetBefore | back to summary |
---|---|
public ZoneOffset getOffsetBefore() Gets the offset before the transition. This is the offset in use before the instant of the transition.
|
getValidOffsets | back to summary |
---|---|
pack-priv List Gets the valid offsets during this transition. A gap will return an empty list, while an overlap will return both offsets.
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Returns a suitable hash code.
|
isGap | back 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
|
isOverlap | back 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
|
isValidOffset | back 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.
|
of | back 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
|
readExternal | back to summary |
---|---|
pack-priv static ZoneOffsetTransition readExternal(DataInput in) throws IOException Reads the state from the stream.
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws InvalidObjectException Defend against malicious streams.
|
toEpochSecond | back to summary |
---|---|
public long toEpochSecond() Gets the transition instant as an epoch second.
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns a string describing this object. |
writeExternal | back to summary |
---|---|
pack-priv void writeExternal(DataOutput out) throws IOException Writes the state to the stream.
|
writeReplace | back to summary |
---|---|
private Object writeReplace() Writes the object using a dedicated serialized form.
|