Enum Class DurationFormat.Style

java.lang.Object
java.lang.Enum<DurationFormat.Style>
org.springframework.format.annotation.DurationFormat.Style
All Implemented Interfaces:
Serializable, Comparable<DurationFormat.Style>, Constable
Enclosing class:
DurationFormat

public static enum DurationFormat.Style extends Enum<DurationFormat.Style>
Duration format styles.
  • Enum Constant Details

    • SIMPLE

      public static final DurationFormat.Style SIMPLE
      Simple formatting based on a short suffix, for example '1s'. Supported unit suffixes are: ns, us, ms, s, m, h, d. This corresponds to nanoseconds, microseconds, milliseconds, seconds, minutes, hours and days respectively.

      Note that when printing a Duration, this style can be lossy if the selected unit is bigger than the resolution of the duration. For example, * Duration.ofMillis(5).plusNanos(1234) would get truncated to "5ms" when printing using ChronoUnit.MILLIS. Fractional durations are not supported.

    • ISO8601

      public static final DurationFormat.Style ISO8601
      ISO-8601 formatting.

      This is what the JDK uses in Duration.parse(CharSequence) and Duration.toString().

    • COMPOSITE

      public static final DurationFormat.Style COMPOSITE
      Like SIMPLE, but allows multiple segments ordered from largest-to-smallest units of time, like 1h12m27s.

      A single minus sign (-) is allowed to indicate the whole duration is negative. Spaces are allowed between segments, and a negative duration with spaced segments can optionally be surrounded by parenthesis after the minus sign, like so: -(34m 57s).

  • Method Details

    • values

      public static DurationFormat.Style[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DurationFormat.Style valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null