Package org.openhab.core.util
Class DurationUtils
java.lang.Object
org.openhab.core.util.DurationUtils
Static utility methods that are helpful when dealing with
Duration
.- Author:
- Jimmy Tanagra - Initial contribution
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
DurationUtils
public DurationUtils()
-
-
Method Details
-
parse
Parses a duration string in ISO-8601 duration format or a custom format like "1d 1h 15m 30s 500ms". When specifying a duration, the units must be specified in the order of days, hours, minutes, seconds, and milliseconds, although any individual unit may be omitted. Each unit must be preceded by an integer value. A space between the number and its corresponding unit is permitted but not required. Likewise, whitespace between unit groups is optional. The units supported in the duration format are:- 'd|day|days' for days,
- 'h|hr|hrs|hour|hours' for hours,
- 'm|min|mins|minute|minutes' for minutes,
- 's|sec|secs|second|seconds' for seconds, and
- 'ms|millisecond|milliseconds' for milliseconds.
- "1h" represents 1 hour
- "15m" represents 15 minutes
- "1h15m" represents 1 day and 15 minutes. It can also be written as "1h 15m", "1 h 15 m", "1 hr 15 mins", "1hour 15 minutes", etc.
- "1d 1h 30s" represents 1 day, 1 hour, and 30 seconds
- "PT1H30M" represents 1 hour and 30 minutes
- "PT1D" represents 1 day
- "PT0.5S" represents 0.5 seconds (500 milliseconds)
- Parameters:
durationString
- the string representation of the duration- Returns:
- a Duration object representing the parsed duration
- Throws:
IllegalArgumentException
- if the string cannot be parsed into a valid duration
-