def duration_to_s(seconds)

    unless seconds.is_a?(::Numeric)
      raise ArgumentError.new("#{seconds} must be a number but is a #{seconds.class}.")
    end

    seconds_in_minute = 60
    seconds_in_hour = 60 * seconds_in_minute
    seconds_in_day = 24 *seconds_in_hour

    str = ''

    if seconds < 0
      str << '-'
      seconds = -seconds
    end

    fractional_second = seconds - Integer(seconds)
    seconds = Integer(seconds)

    days = seconds / seconds_in_day
    print_days = days > 0
    seconds %= seconds_in_day

    hours = seconds / seconds_in_hour
    print_hours = hours > 0 || days > 0
    seconds %= seconds_in_hour

    minutes = seconds / seconds_in_minute
    print_minutes = minutes > 0 || hours > 0 || days > 0
    seconds %= seconds_in_minute

    str << "#{days} d, "     if print_days
    str << "#{hours} h, "    if print_hours
    str << "#{minutes} m, "  if print_minutes
    str << "#{seconds + fractional_second} s"

    str
  end
def duration_to_s(seconds)

    unless seconds.is_a?(::Numeric)
      raise ArgumentError.new("#{seconds} must be a number but is a #{seconds.class}.")
    end

    seconds_in_minute = 60
    seconds_in_hour = 60 * seconds_in_minute
    seconds_in_day = 24 *seconds_in_hour

    str = ''

    if seconds < 0
      str << '-'
      seconds = -seconds
    end

    fractional_second = seconds - Integer(seconds)
    seconds = Integer(seconds)

    days = seconds / seconds_in_day
    print_days = days > 0
    seconds %= seconds_in_day

    hours = seconds / seconds_in_hour
    print_hours = hours > 0 || days > 0
    seconds %= seconds_in_hour

    minutes = seconds / seconds_in_minute
    print_minutes = minutes > 0 || hours > 0 || days > 0
    seconds %= seconds_in_minute

    str << "#{days} d, "     if print_days
    str << "#{hours} h, "    if print_hours
    str << "#{minutes} m, "  if print_minutes
    str << "#{seconds + fractional_second} s"

    str
  end
Formats a number of seconds as a succinct string, with days, hours,
 minutes, and seconds.  Examples:

 duration_to_s(1_000_000)  => "11 d, 13 h, 46 m, 40 s"
 duration_to_s(1_000)      => "16 m, 40 s"
 duration_to_s(-1_000)     => "-16 m, 40 s"
 duration_to_s(1.234567)   => "1.234567 s"
 duration_to_s(1000.234567) => "16 m, 40.23456699999997 s"