Class ZoneOffsetInfo
The mapping from a local date-time to an offset is not straightforward. There are three cases:
- Normal. Where there is a single offset for the local date-time.
- Gap. Where there is a gap in the local time-line typically caused by the spring cutover to daylight savings. There are no valid offsets within the gap
- Overlap. Where there is a gap in the local time-line typically caused by the autumn cutover from daylight savings. There are two valid offsets during the overlap.
isTransition()
method to handle the gap and overlap. Alternatively use one of the general
methods getEstimatedOffset()
or isValidOffset(ZoneOffset)
.
OffsetInfo is immutable and thread-safe.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LocalDateTime
The date-time that this info applies to.private final ZoneOffset
The offset for the local time-line.private final ZoneOffsetTransition
The transition between two offsets on the local time-line. -
Constructor Summary
ConstructorsConstructorDescriptionZoneOffsetInfo
(LocalDateTime dateTime, ZoneOffset offset, ZoneOffsetTransition transition) Creates an instance handling a simple single offset. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if this object equals another.Gets an estimated offset for the local date-time.Gets the local date-time that this info is applicable to.Gets the offset applicable at this point on the local time-line.Gets information about the transition occurring on the local time-line.int
hashCode()
A suitable hash code for this object.boolean
Is a transition occurring on the local time-line.boolean
isValidOffset
(ZoneOffset offset) Checks if the specified offset is valid for this date-time.static ZoneOffsetInfo
of
(LocalDateTime dateTime, ZoneOffset offset, ZoneOffsetTransition transition) Creates an instance representing a simple single offset or a transition.toString()
Returns a string describing this object.
-
Field Details
-
dateTime
The date-time that this info applies to. -
offset
The offset for the local time-line. -
transition
The transition between two offsets on the local time-line.
-
-
Constructor Details
-
ZoneOffsetInfo
ZoneOffsetInfo(LocalDateTime dateTime, ZoneOffset offset, ZoneOffsetTransition transition) Creates an instance handling a simple single offset.- Parameters:
dateTime
- the local date-time that this info applies to, not nulloffset
- the offset applicable at the date-time, not null
-
-
Method Details
-
of
public static ZoneOffsetInfo of(LocalDateTime dateTime, ZoneOffset offset, ZoneOffsetTransition transition) Creates an instance representing a simple single offset or a transition.Applications should normally obtain an instance from
ZoneRules
. This constructor is intended for use by implementors ofZoneRules
.One, and only one, of the
offset
ortransition
parameters must be specified.- Parameters:
dateTime
- the local date-time that this info applies to, not nulloffset
- the offset applicable at the date-timetransition
- the details of the transition including the offset before and after
-
getLocalDateTime
Gets the local date-time that this info is applicable to.- Returns:
- the date-time that this is the information for, not null
-
isTransition
public boolean isTransition()Is a transition occurring on the local time-line.A transition may be a gap or overlap and is normally caused by daylight savings cutover.
- Returns:
- true if there is a transition occurring on the local time-line, false if there is a single valid offset
-
getOffset
Gets the offset applicable at this point on the local time-line.This method is intended for use when
isTransition()
returnsfalse
.- Returns:
- the offset applicable when there is not a transition on the local-time line, null if it is a transition
-
getTransition
Gets information about the transition occurring on the local time-line.This method is intended for use when
isTransition()
returnstrue
- Returns:
- the transition on the local-time line, null if not a transition
-
getEstimatedOffset
Gets an estimated offset for the local date-time.This returns an offset that applies at the local date-time or just after. During a gap the offset after the gap will be returned. During an overlap the offset after the transition will be returned.
- Returns:
- a suitable estimated offset, never null
-
isValidOffset
Checks if the specified offset is valid for this date-time.The date-time will typically have a single valid offset. During a gap, there will be no valid offsets. During an overlap, there will be two valid offsets. This method returns
true
if the specified offset is one of the valid offsets.- Parameters:
offset
- the offset to check, null returns false- Returns:
- true if the offset is one of those allowed by the date-time
-
equals
Checks if this object equals another.The entire state of the object is compared.
-
hashCode
public int hashCode()A suitable hash code for this object. -
toString
Returns a string describing this object.
-