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
  # Convert weeks to days and remove weeks if mixed with date parts
  if week_mixed_with_date?(parts)
    parts[:days] += parts.delete(:weeks) * SECONDS_PER_WEEK / SECONDS_PER_DAY
  end
  parts
end