Class ZoneOffsetTransition

java.lang.Object
javax.time.calendar.zone.ZoneOffsetTransition
All Implemented Interfaces:
Serializable, Comparable<ZoneOffsetTransition>

public final class ZoneOffsetTransition extends Object implements Comparable<ZoneOffsetTransition>, 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. ZoneOffsetTransition models the transition between the two offsets.

Gaps occur where there are local date-times that simply do not 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'.

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

ZoneOffsetTransition is immutable and thread-safe.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      A serialization identifier for this class.
      See Also:
    • transition

      private final OffsetDateTime transition
      The transition date-time with the offset before the transition.
    • transitionAfter

      private final OffsetDateTime transitionAfter
      The transition date-time with the offset after the transition.
  • Constructor Details

    • ZoneOffsetTransition

      ZoneOffsetTransition(OffsetDateTime transition, ZoneOffset offsetAfter)
      Creates an instance defining a transition between two offsets.
      Parameters:
      transition - the transition date-time with the offset before the transition, not null
      offsetAfter - the offset at and after the transition, not null
  • Method Details

    • of

      public static ZoneOffsetTransition of(OffsetDateTime transition, ZoneOffset offsetAfter)
      Obtains an instance defining a transition between two offsets.

      Applications should normally obtain an instance from ZoneRules. This constructor is intended for use by implementors of ZoneRules.

      Parameters:
      transition - the transition date-time with the offset before the transition, not null
      offsetAfter - the offset at and after the transition, not null
    • writeReplace

      private Object writeReplace()
      Uses a serialization delegate.
      Returns:
      the replacing object, never null
    • writeExternal

      void writeExternal(DataOutput out) throws IOException
      Writes the state to the stream.
      Parameters:
      out - the output stream, not null
      Throws:
      IOException - if an error occurs
    • readExternal

      static ZoneOffsetTransition readExternal(DataInput in) throws IOException
      Reads the state from the stream.
      Parameters:
      in - the input stream, not null
      Returns:
      the created object, never null
      Throws:
      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() and getDateTimeAfter() all represent the same instant.

      Returns:
      the transition instant, not null
    • getLocal

      public LocalDateTime getLocal()
      Gets the local date-time at the transition which is expressed relative to the 'before' offset.

      This is the date-time where the discontinuity begins. For a gap, this local date-time never occurs, whereas for an overlap it occurs just once after the entire transition is complete. This method is simply getDateTime().toLocalDateTime()

      This value expresses the date-time normally used in verbal communications. For example 'the clocks will move forward one hour tonight at 1am' (a gap) or 'the clocks will move back one hour tonight at 2am' (an overlap).

      Returns:
      the local date-time of the transition, expressed relative to the before offset, not null
    • getDateTimeBefore

      public OffsetDateTime getDateTimeBefore()
      Gets the transition instant date-time 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 this is an invalid date-time.

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

      Returns:
      the transition date-time expressed with the before offset, not null
    • getDateTimeAfter

      public OffsetDateTime getDateTimeAfter()
      Gets the transition date-time expressed with the 'after' offset.

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

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

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

      public Period getTransitionSize()
      Gets the length of the transition as a Period.

      This will typically be one hour, but might not be. It will be positive for a gap and negative for an overlap.

      Returns:
      the length of the transition, positive for gaps, negative for overlaps
    • 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 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:
      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:00 to +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
    • 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:
      compareTo in interface 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(Object other)
      Checks if this object equals another.

      The entire state of the object is compared.

      Overrides:
      equals in class 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:
      hashCode in class Object
      Returns:
      the hash code
    • toString

      public String toString()
      Returns a string describing this object.
      Overrides:
      toString in class Object
      Returns:
      a string for debugging, never null