Class ZoneResolvers.PostGapPreOverlap
- Enclosing class:
- ZoneResolvers
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected OffsetDateTime
handleGap
(TimeZone zone, ZoneRules rules, ZoneOffsetTransition discontinuity, LocalDateTime newDateTime, OffsetDateTime oldDateTime) Defines the strategy for selecting an offset to use for a local date-time when the local date-time is in a local time-line gap.protected OffsetDateTime
handleOverlap
(TimeZone zone, ZoneRules rules, ZoneOffsetTransition discontinuity, LocalDateTime newDateTime, OffsetDateTime oldDateTime) Defines the strategy for selecting an offset to use for a local date-time when the local date-time is in a local time-line overlap.Methods inherited from class javax.time.calendar.ZoneResolver
resolve
-
Field Details
-
INSTANCE
The singleton instance.
-
-
Constructor Details
-
PostGapPreOverlap
private PostGapPreOverlap()
-
-
Method Details
-
handleGap
protected OffsetDateTime handleGap(TimeZone zone, ZoneRules rules, ZoneOffsetTransition discontinuity, LocalDateTime newDateTime, OffsetDateTime oldDateTime) Defines the strategy for selecting an offset to use for a local date-time when the local date-time is in a local time-line gap.Implementations of method handles missing date-times by either throwing an exception or changing the local date-time.
Information is provided to assist with the strategy. This includes the zone rules, information about the gap and the old date-time.
The old date-time is provided if this strategy is called as a result of an adjustment, such as changing a field, addition or subtraction. This parameter will be null if there is no original date-time, such as during construction of a
ZonedDateTime
.After the completion of this method, the result will be validated.
A typical implementation might be:
return gapInfo.getDateTimeAfter();
This implementation works by returning the first valid date-time after the gap.- Specified by:
handleGap
in classZoneResolver
- Parameters:
zone
- the time-zone, not nullrules
- the applicable zone rules, not nulldiscontinuity
- the information about the gap for the newDateTime, not nullnewDateTime
- the new local date-time, not nulloldDateTime
- the old offset date-time before the adjustment, may be null- Returns:
- the resolved offset date-time, never null
-
handleOverlap
protected OffsetDateTime handleOverlap(TimeZone zone, ZoneRules rules, ZoneOffsetTransition discontinuity, LocalDateTime newDateTime, OffsetDateTime oldDateTime) Defines the strategy for selecting an offset to use for a local date-time when the local date-time is in a local time-line overlap.Implementations of method handle overlapping date-times by throwing an exception, selecting the appropriate offset or changing the local date-time. Two additional parameters are available to help with the logic.
Firstly, the discontinuity, which represents the discontinuity in the local time-line that needs to be resolved. This is the result from
zone.getOffsetInfo(newDateTime)
and is provided to improve performance.Secondly, the old date-time, which is the original offset date-time that any adjustment started from. Example adjustments are changing a field, addition or subtraction. This parameter will be null if there is no original date-time, such as during construction.
After the completion of this method, the result will be validated.
A typical implementation might be:
if (oldDateTime != null && discontinuity.containsOffset(oldDateTime.getOffset())) { return OffsetDateTime.dateTime(newDateTime, oldDateTime.getOffset()); } return OffsetDateTime.dateTime(newDateTime, discontinuity.getOffsetBefore());
This implementation handles the overlap by attempting to keep the result offset in the same offset as the old date-time. Otherwise, it returns the earlier of the two offsets.- Specified by:
handleOverlap
in classZoneResolver
- Parameters:
zone
- the time-zone, not nullrules
- the applicable zone rules, not nulldiscontinuity
- the information about the overlap for the newDateTime, not nullnewDateTime
- the new local date-time, not nulloldDateTime
- the old offset date-time before the adjustment, may be null- Returns:
- the resolved offset date-time, never null
-