class ActiveSupport::Duration::ISO8601Serializer

def normalize

If all parts are negative it will negate all of them and return minus as a sign.
Zero parts are removed as not significant.
Parts are summarized (as they can become repetitive due to addition, etc).
Return pair of duration's parts and whole duration sign.
def normalize
  parts = @duration.parts.each_with_object(Hash.new(0)) do |(k,v),p|
    p[k] += v  unless v.zero?
  end
  # If all parts are negative - let's make a negative duration
  sign = ''
  if parts.values.all? { |v| v < 0 }
    sign = '-'
    parts.transform_values!(&:-@)
  end
  [parts, sign]
end