class Numeric

Number helpers

Public Instance Methods

format_time(human: false) click to toggle source

Format human readable time from seconds

@param seconds [Integer] Seconds

# File lib/doing/chronify/numeric.rb, line 13
def format_time(human: false)
  return [0, 0, 0] if nil?

  seconds = dup.to_i
  minutes = (seconds / 60).to_i
  hours = (minutes / 60).to_i
  if human
    minutes = (minutes % 60).to_i
    [0, hours, minutes]
  else
    days = (hours / 24).to_i
    hours = (hours % 24).to_i
    minutes = (minutes % 60).to_i
    [days, hours, minutes]
  end
end
time_string(format: :dhm) click to toggle source

Format seconds as natural language time string

@param format [Symbol] The format to output (:dhm, :hm, :m, :clock, :natural)

# File lib/doing/chronify/numeric.rb, line 36
def time_string(format: :dhm)
  format_time(human: true).time_string(format: format)
end