class ActiveSupport::Duration

def parse(iso8601duration)

If invalid string is provided, it will raise +ActiveSupport::Duration::ISO8601Parser::ParsingError+.
This method allows negative parts to be present in pattern.
See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.

Creates a new Duration from string formatted according to ISO 8601 Duration.
def parse(iso8601duration)
  parts = ISO8601Parser.new(iso8601duration).parse!
  new(calculate_total_seconds(parts), parts)
end