Class DurationFormat

    • Method Detail

      • partDelimiter

        public abstract String partDelimiter()
        The delimiter to use to separate each part of the formatted value.
        Returns:
        the formatted-part delimiter.
      • numberFormat

        public abstract NumberFormat numberFormat()
        The NumberFormat which the DurationFormatter will use when formatting individual parts of Duration values.

        Note: the rounding mode and number of fraction digits properties of this NumberFormat instance will be ignored.

        Instead, the DurationFormatter will use a minimumFractionDigits of zero and a maximumFractionDigits value of zero for all parts of the value other than the part corresponding to the smallestUnit. For the value corresponding to the smallestUnit, the maximumFractionDigits will be set to numFractionalDigits(), rounding mode will be set based on remainderHandling(), and minimumFractionDigits will be to zero.

        Returns:
        the NumberFormat.
      • largestUnit

        public abstract ChronoUnit largestUnit()
        The largest allowable unit of time to use when formatting the Duration value.
        Returns:
        The largest allowable unit to use.
      • smallestUnit

        public abstract ChronoUnit smallestUnit()
        The smallest allowable unit of time to use when formatting the Duration value. Leading and trailing parts of the formatted value with a quantity of zero will not be shown.
        Returns:
        The smallest allowable unit to use.
      • unitForZeroDuration

        public abstract ChronoUnit unitForZeroDuration()
        The unit of time to use when formatting a Duration value of zero.
        Returns:
        The largest allowable unit to use.
      • suppressedUnits

        public abstract Set<ChronoUnit> suppressedUnits()
        Get the set of units that should not be included in the list of allowed units, even if they fall within the range described by the smallestUnit and largestUnit properties.
        Returns:
        The set of units which should not be used when formatting duration values.
      • numFractionalDigits

        public abstract Integer numFractionalDigits()
        Set the maximum number of digits to use to represent a fractional amount of the smallest allowed unit. This value is used instead of the value of NumberFormat.getMaximumIntegerDigits() in numberFormat().

        Example: 36 hours formatted in units of days with a numFractionalDigits value of 2 will be represented as 1.5 days.

        Returns:
        The maximum number of fractional digits to use when formatting the value of the smallest allowed unit.
      • remainderHandling

        public abstract DurationRemainderHandling remainderHandling()
        Specify how values that are smaller than the smallest allowed unit with its fractional digits are handled.

        Example: A duration of 19 microseconds is formatted in units of hours, minutes, seconds, and milliseconds, with a numFractionalDigits value of 2. 19 microseconds is equal to 0.019 milliseconds, but using only two digits to the right of the decimal, should that be formatted as 0.01 or 0.02? DurationRemainderHandling.TRUNCATE will drop the 0.009 milliseconds; DurationRemainderHandling.ROUND_HALF_EVEN will round the 0.009 milliseconds up to 0.01, for a formatted value of 0.02 milliseconds.

        Returns:
        The DurationRemainderHandling value that will control how rounding is performed.
      • units

        @Memoized
        public List<ChronoUnit> units()
        Get a list of units which are greater than or equal to smallestUnit and less than or equal to largestUnit, without the units specified by suppressedUnits(). These units are the ones that will be treated as available for formatting values. Units not in this list will not be used by the DurationFormatter.
        Returns:
        The list of available units for formatting.
      • builder

        public static DurationFormat.Builder builder()
        Create an object that will build a DurationFormatter instance.

        This builder is mostly unconfigured, except for the following default values:

        • suppressedUnits = { ChronoUnit.HALF_DAYS }
        • remainderHandling = DurationRemainderHandling.TRUNCATE
        Returns:
        a new DurationFormat.Builder instance.
      • builder

        public static DurationFormat.Builder builder​(DurationFormat format)
        Create an object that will build a DurationFormatter instance.

        This new builder is configured with the values taken from the format parameter. In effect, it is a mutable copy of that instance.

        Parameters:
        format - The format to use to configure the new Builder instance.
        Returns:
        a new DurationFormat.Builder instance, with the same values as the instance passed via the format parameter.