Class ZoneOffsetTransition
- java.lang.Object
-
- org.threeten.bp.zone.ZoneOffsetTransition
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<ZoneOffsetTransition>
public final class ZoneOffsetTransition extends java.lang.Object implements java.lang.Comparable<ZoneOffsetTransition>, java.io.Serializable
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.
ZoneOffsetTransitionmodels 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:00to+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:00to+03:00. This might be described as 'the clocks will move back one hour tonight at 2am'.Specification for implementors
This class is immutable and thread-safe.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private ZoneOffsetoffsetAfterThe offset after transition.private ZoneOffsetoffsetBeforeThe offset before transition.private static longserialVersionUIDSerialization version.private LocalDateTimetransitionThe local transition date-time at the transition.
-
Constructor Summary
Constructors Constructor Description ZoneOffsetTransition(long epochSecond, ZoneOffset offsetBefore, ZoneOffset offsetAfter)Creates an instance from epoch-second and offsets.ZoneOffsetTransition(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter)Creates an instance defining a transition between two offsets.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ZoneOffsetTransition transition)Compares this transition to another based on the transition instant.booleanequals(java.lang.Object other)Checks if this object equals another.LocalDateTimegetDateTimeAfter()Gets the local transition date-time, as would be expressed with the 'after' offset.LocalDateTimegetDateTimeBefore()Gets the local transition date-time, as would be expressed with the 'before' offset.DurationgetDuration()Gets the duration of the transition.private intgetDurationSeconds()Gets the duration of the transition in seconds.InstantgetInstant()Gets the transition instant.ZoneOffsetgetOffsetAfter()Gets the offset after the transition.ZoneOffsetgetOffsetBefore()Gets the offset before the transition.(package private) java.util.List<ZoneOffset>getValidOffsets()Gets the valid offsets during this transition.inthashCode()Returns a suitable hash code.booleanisGap()Does this transition represent a gap in the local time-line.booleanisOverlap()Does this transition represent a gap in the local time-line.booleanisValidOffset(ZoneOffset offset)Checks if the specified offset is valid during this transition.static ZoneOffsetTransitionof(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter)Obtains an instance defining a transition between two offsets.(package private) static ZoneOffsetTransitionreadExternal(java.io.DataInput in)Reads the state from the stream.longtoEpochSecond()Gets the transition instant as an epoch second.java.lang.StringtoString()Returns a string describing this object.(package private) voidwriteExternal(java.io.DataOutput out)Writes the state to the stream.private java.lang.ObjectwriteReplace()Uses a serialization delegate.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization version.- See Also:
- Constant Field Values
-
transition
private final LocalDateTime transition
The local transition date-time at the transition.
-
offsetBefore
private final ZoneOffset offsetBefore
The offset before transition.
-
offsetAfter
private final ZoneOffset offsetAfter
The offset after transition.
-
-
Constructor Detail
-
ZoneOffsetTransition
ZoneOffsetTransition(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter)
Creates an instance defining a transition between two offsets.- Parameters:
transition- the transition date-time with the offset before the transition, not nulloffsetBefore- the offset before the transition, not nulloffsetAfter- the offset at and after the transition, not null
-
ZoneOffsetTransition
ZoneOffsetTransition(long epochSecond, ZoneOffset offsetBefore, ZoneOffset offsetAfter)Creates an instance from epoch-second and offsets.- Parameters:
epochSecond- the transition epoch-secondoffsetBefore- the offset before the transition, not nulloffsetAfter- the offset at and after the transition, not null
-
-
Method Detail
-
of
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 creatingZoneRules.- Parameters:
transition- the transition date-time at the transition, which never actually occurs, expressed local to the before offset, not nulloffsetBefore- the offset before the transition, not nulloffsetAfter- the offset at and after the transition, not null- Returns:
- the transition, not null
- Throws:
java.lang.IllegalArgumentException- ifoffsetBeforeandoffsetAfterare equal, ortransition.getNano()returns non-zero value
-
writeReplace
private java.lang.Object writeReplace()
Uses a serialization delegate.- Returns:
- the replacing object, not null
-
writeExternal
void writeExternal(java.io.DataOutput out) throws java.io.IOExceptionWrites the state to the stream.- Parameters:
out- the output stream, not null- Throws:
java.io.IOException- if an error occurs
-
readExternal
static ZoneOffsetTransition readExternal(java.io.DataInput in) throws java.io.IOException
Reads the state from the stream.- Parameters:
in- the input stream, not null- Returns:
- the created object, not null
- Throws:
java.io.IOException- if an error occurs
-
getInstant
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()andgetDateTimeAfter()all represent the same instant.- Returns:
- the transition instant, not null
-
toEpochSecond
public long toEpochSecond()
Gets the transition instant as an epoch second.- Returns:
- the transition epoch second
-
getDateTimeBefore
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:
- the transition date-time expressed with the before offset, not null
-
getDateTimeAfter
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:
- the transition date-time expressed with the after offset, not null
-
getOffsetBefore
public ZoneOffset getOffsetBefore()
Gets the offset before the transition.This is the offset in use before the instant of the transition.
- Returns:
- the offset before the transition, not null
-
getOffsetAfter
public ZoneOffset getOffsetAfter()
Gets the offset after the transition.This is the offset in use on and after the instant of the transition.
- Returns:
- the offset after the transition, not null
-
getDuration
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:
- the duration of the transition, positive for gaps, negative for overlaps
-
getDurationSeconds
private int getDurationSeconds()
Gets the duration of the transition in seconds.- Returns:
- the duration in seconds
-
isGap
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:00to+02:00. This might be described as 'the clocks will move forward one hour tonight at 1am'.- Returns:
- true if this transition is a gap, false if it is an overlap
-
isOverlap
public boolean isOverlap()
Does this transition represent a gap 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:00to+01:00. This might be described as 'the clocks will move back one hour tonight at 2am'.- Returns:
- true if this transition is an overlap, false if it is a gap
-
isValidOffset
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- the offset to check, null returns false- Returns:
- true if the offset is valid during the transition
-
getValidOffsets
java.util.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:
- the list of valid offsets
-
compareTo
public int compareTo(ZoneOffsetTransition transition)
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.
- Specified by:
compareToin interfacejava.lang.Comparable<ZoneOffsetTransition>- Parameters:
transition- the transition to compare to, not null- Returns:
- the comparator value, negative if less, positive if greater
-
equals
public boolean equals(java.lang.Object other)
Checks if this object equals another.The entire state of the object is compared.
- Overrides:
equalsin classjava.lang.Object- Parameters:
other- the other object to compare to, null returns false- Returns:
- true if equal
-
hashCode
public int hashCode()
Returns a suitable hash code.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code
-
toString
public java.lang.String toString()
Returns a string describing this object.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string for debugging, not null
-
-