Class ZoneOffsetInfo
- java.lang.Object
-
- javax.time.calendar.zone.ZoneOffsetInfo
-
public final class ZoneOffsetInfo extends java.lang.Object
Information about the valid offsets applicable for a local date-time.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 methodsgetEstimatedOffset()
orisValidOffset(ZoneOffset)
.OffsetInfo is immutable and thread-safe.
-
-
Field Summary
Fields Modifier and Type Field Description private LocalDateTime
dateTime
The date-time that this info applies to.private ZoneOffset
offset
The offset for the local time-line.private ZoneOffsetTransition
transition
The transition between two offsets on the local time-line.
-
Constructor Summary
Constructors Constructor Description ZoneOffsetInfo(LocalDateTime dateTime, ZoneOffset offset, ZoneOffsetTransition transition)
Creates an instance handling a simple single offset.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object otherInfo)
Checks if this object equals another.ZoneOffset
getEstimatedOffset()
Gets an estimated offset for the local date-time.LocalDateTime
getLocalDateTime()
Gets the local date-time that this info is applicable to.ZoneOffset
getOffset()
Gets the offset applicable at this point on the local time-line.ZoneOffsetTransition
getTransition()
Gets information about the transition occurring on the local time-line.int
hashCode()
A suitable hash code for this object.boolean
isTransition()
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.java.lang.String
toString()
Returns a string describing this object.
-
-
-
Field Detail
-
dateTime
private final LocalDateTime dateTime
The date-time that this info applies to.
-
offset
private final ZoneOffset offset
The offset for the local time-line.
-
transition
private final ZoneOffsetTransition transition
The transition between two offsets on the local time-line.
-
-
Constructor Detail
-
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 Detail
-
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
public LocalDateTime 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
public ZoneOffset 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
public ZoneOffsetTransition 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
public ZoneOffset 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
public boolean isValidOffset(ZoneOffset offset)
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
public boolean equals(java.lang.Object otherInfo)
Checks if this object equals another.The entire state of the object is compared.
- Overrides:
equals
in classjava.lang.Object
- Parameters:
otherInfo
- the other object to compare to, null returns false- Returns:
- true if equal
-
hashCode
public int hashCode()
A suitable hash code for this object.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code
-
toString
public java.lang.String toString()
Returns a string describing this object.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string for debugging, never null
-
-