Class ZoneResolvers.PreTransition

java.lang.Object
javax.time.calendar.ZoneResolver
javax.time.calendar.ZoneResolvers.PreTransition
Enclosing class:
ZoneResolvers

private static class ZoneResolvers.PreTransition extends ZoneResolver
Class implementing preTransition resolver.
  • Field Details

    • INSTANCE

      private static final ZoneResolver INSTANCE
      The singleton instance.
  • Constructor Details

    • PreTransition

      private PreTransition()
  • 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 class ZoneResolver
      Parameters:
      zone - the time-zone, not null
      rules - the applicable zone rules, not null
      discontinuity - the information about the gap for the newDateTime, not null
      newDateTime - the new local date-time, not null
      oldDateTime - 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 class ZoneResolver
      Parameters:
      zone - the time-zone, not null
      rules - the applicable zone rules, not null
      discontinuity - the information about the overlap for the newDateTime, not null
      newDateTime - the new local date-time, not null
      oldDateTime - the old offset date-time before the adjustment, may be null
      Returns:
      the resolved offset date-time, never null