Class DurationUtils

java.lang.Object
org.nuxeo.common.utils.DurationUtils

public final class DurationUtils extends Object
Since:
11.1
  • Field Details

    • DURATION_SIMPLE_FORMAT

      public static final Pattern DURATION_SIMPLE_FORMAT
  • Method Details

    • parse

      public static Duration parse(String value)
      Obtains a Duration from a text string such as PnDTnHnMn.nS or _d_h_m_s_ms.

      See Duration.parse(CharSequence) for PnDTnHnMn.nS format.

      For _d_h_m_s_ms, there are five sections, each consisting of a number and a suffix. The suffixes are "d", "h", "m", "s" and "ms" for days, hours, minutes, seconds and milliseconds. The suffixes must occur in order and at least one of them must be present.

      Throws:
      DateTimeParseException - if the text cannot be parsed to a duration
      See Also:
    • parsePositive

      public static Duration parsePositive(String value, Duration defaultDuration)
      Obtains a Duration from a text string according to parse(String), but in case of invalid, zero or negative duration returns a default.
      Parameters:
      value - the value to parse
      defaultDuration - the default duration to return for invalid, zero or negative duration
      Returns:
      the parsed duration (positive), or the default
      Since:
      11.1