Skip to main content

duration

duration(text: String) : Duration

Obtains a Duration from a String that represents a duration according to the ISO 8601 standard. For example, duration("PT23H56M4S") returns a Duration that represents 23 hours, 56 minutes, and 4 seconds.

This function will raise an error if the string significantly deviates from the ISO 8601 standard. A permitted deviation is for strings that represent a negative interval of time. This function accepts strings like "-P1DT12H", "P-1DT-12H", and "P-2DT12H", which all represent -36 hours.

This function will also raise an error if the string represents a duration with a nonzero amount of nanoseconds, such as the string "PT0.5S".

See also

Functions

Types