class ActiveSupport::Duration::ISO8601Parser

def validate!

Checks for various semantic errors as stated in ISO 8601 standard.
def validate!
  raise_parsing_error("is empty duration") if parts.empty?
  # Mixing any of Y, M, D with W is invalid.
  if parts.key?(:weeks) && (parts.keys & DATE_COMPONENTS).any?
    raise_parsing_error("mixing weeks with other date parts not allowed")
  end
  # Specifying an empty T part is invalid.
  if mode == :time && (parts.keys & TIME_COMPONENTS).empty?
    raise_parsing_error("time part marker is present but time part is empty")
  end
  fractions = parts.values.reject(&:zero?).select { |a| (a % 1) != 0 }
  unless fractions.empty? || (fractions.size == 1 && fractions.last == @parts.values.reject(&:zero?).last)
    raise_parsing_error "(only last part can be fractional)"
  end
  true
end