Class ZoneResolvers


  • public final class ZoneResolvers
    extends java.lang.Object
    Provides common implementations of ZoneResolver.

    A ZoneResolver provides a strategy for handling the gaps and overlaps on the time-line that occur due to changes in the offset from UTC, usually caused by Daylight Savings Time.

    ZoneResolvers is a utility class. All resolvers returned are immutable and thread-safe.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ZoneResolvers()
      Private constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ZoneResolver combination​(ZoneResolver gapResolver, ZoneResolver overlapResolver)
      Creates a combined resolver, using two different strategies for gap and overlap.
      static ZoneResolver postGapPreOverlap()
      Returns the post-gap-pre-overlap zone resolver, which returns the instant after the transition for gaps, and the earlier offset for overlaps.
      static ZoneResolver postTransition()
      Returns the post-transition zone resolver, which returns the instant after the transition for gaps, and the later offset for overlaps.
      static ZoneResolver preTransition()
      Returns the pre-transition zone resolver, which returns the instant one nanosecond before the transition for gaps, and the earlier offset for overlaps.
      static ZoneResolver pushForward()
      Returns the push forward resolver, which changes the time of the result in a gap by adding the lenth of the gap.
      static ZoneResolver retainOffset()
      Returns the retain offset resolver, which returns the instant after the transition for gaps, and the same offset for overlaps.
      static ZoneResolver strict()
      Returns the strict zone resolver which rejects all gaps and overlaps as invalid, resulting in an exception.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ZoneResolvers

        private ZoneResolvers()
        Private constructor.
    • Method Detail

      • strict

        public static ZoneResolver strict()
        Returns the strict zone resolver which rejects all gaps and overlaps as invalid, resulting in an exception.
        Returns:
        the strict resolver, never null
      • preTransition

        public static ZoneResolver preTransition()
        Returns the pre-transition zone resolver, which returns the instant one nanosecond before the transition for gaps, and the earlier offset for overlaps.
        Returns:
        the pre-transition resolver, never null
      • postTransition

        public static ZoneResolver postTransition()
        Returns the post-transition zone resolver, which returns the instant after the transition for gaps, and the later offset for overlaps.
        Returns:
        the post-transition resolver, never null
      • postGapPreOverlap

        public static ZoneResolver postGapPreOverlap()
        Returns the post-gap-pre-overlap zone resolver, which returns the instant after the transition for gaps, and the earlier offset for overlaps.
        Returns:
        the post-transition resolver, never null
      • retainOffset

        public static ZoneResolver retainOffset()
        Returns the retain offset resolver, which returns the instant after the transition for gaps, and the same offset for overlaps.

        This resolver is the same as the {postTransition() resolver with one additional rule. When processing an overlap, this resolver attempts to use the same offset as the offset specified in the old date-time. If that offset is invalid then the later offset is chosen

        This resolver is most commonly useful when adding or subtracting time from a ZonedDateTime.

        Returns:
        the retain offset resolver, never null
      • pushForward

        public static ZoneResolver pushForward()
        Returns the push forward resolver, which changes the time of the result in a gap by adding the lenth of the gap.

        If the discontinuity is a gap, then the resolver will add the length of the gap in seconds to the local time. For example, given a gap from 01:00 to 02:00 and a time of 01:20, this will add one hour to result in 02:20.

        If the discontinuity is an overlap, then the resolver will choose the later of the two offsets.

        Returns:
        the push forward resolver, never null
      • combination

        public static ZoneResolver combination​(ZoneResolver gapResolver,
                                               ZoneResolver overlapResolver)
        Creates a combined resolver, using two different strategies for gap and overlap.

        If either argument is null then the strict() resolver is used.

        Parameters:
        gapResolver - the resolver to use for a gap, null means strict
        overlapResolver - the resolver to use for an overlap, null means strict
        Returns:
        the combination resolver, never null