Class PeriodAndDuration

java.lang.Object
org.nuxeo.common.utils.PeriodAndDuration
All Implemented Interfaces:
TemporalAmount

public final class PeriodAndDuration extends Object implements TemporalAmount
The combination of a Period and a Duration.

This allows the representation of ISO 8601 "durations", which comprise a nominal duration (Java Period, i.e., years, months, days), and an accurate duration (Java Duration, i.e., hours, minutes, seconds).

Since:
11.1
  • Field Details

    • ZERO

      public static final PeriodAndDuration ZERO
      A constant for a period and duration of zero.
    • UNITS

      protected static final List<TemporalUnit> UNITS
      The set of supported units. This is the concatenation of the units supported by Period and Duration.
    • PATTERN

      protected static final Pattern PATTERN
    • SECONDS_PER_MINUTE

      protected static final int SECONDS_PER_MINUTE
      See Also:
    • SECONDS_PER_HOUR

      protected static final int SECONDS_PER_HOUR
      See Also:
    • period

      public final Period period
    • duration

      public final Duration duration
  • Constructor Details

  • Method Details

    • getUnits

      public List<TemporalUnit> getUnits()
      Specified by:
      getUnits in interface TemporalAmount
    • get

      public long get(TemporalUnit unit)
      Specified by:
      get in interface TemporalAmount
    • addTo

      public Temporal addTo(Temporal temporal)
      Specified by:
      addTo in interface TemporalAmount
    • subtractFrom

      public Temporal subtractFrom(Temporal temporal)
      Specified by:
      subtractFrom in interface TemporalAmount
    • parse

      public static PeriodAndDuration parse(String text)
      Obtains a PeriodAndDuration from a text string.

      This will parse the string based on the ISO-8601 period format PnYnMnDTnHnMnS. A leading minus sign, and negative values for the units, are allowed.

      Parameters:
      text - the text to parse, not null
      Returns:
      the period and duration (never null)
      Throws:
      DateTimeParseException - if the text cannot be parsed to a period and duration
      See Also:
    • parseInt

      protected static int parseInt(String string, String text, String errorText)
    • parseNumber

      protected static long parseNumber(String string, int multiplier, String text, String errorText)
    • parseFraction

      protected static int parseFraction(String string, int sign, String text)
    • toString

      public String toString()
      Outputs this period and duration as a String, such as P6Y3M1DT4H12M5.636224S.

      The output will be in the ISO-8601 period format. A zero period will be represented as zero seconds, "PT0S".

      Overrides:
      toString in class Object
      Returns:
      a string representation of this period, not null
      See Also: