class Rufus::Scheduler

def self.to_duration_hash(seconds, options={})


from the result
* :drop_seconds, if set to true, seconds and milliseconds will be trimmed
account when building up the result
* :months, if set to true, months (M) of 30 days will be taken into

Options are :

the scene.
This method is used by to_duration_string (to_time_string) behind

# => { :w => 4, :d => 2, :s => 1, :ms => "120" }
Rufus.to_duration_hash 0.120 + 30 * 24 * 3600 + 1
# => { :s => 7, :ms => "51" }
Rufus.to_duration_hash 7.051
# => { :ms => "51" }
Rufus.to_duration_hash 0.051

Turns a number of seconds (integer or Float) into a hash like in :
def self.to_duration_hash(seconds, options={})
  h = {}
  if seconds.is_a?(Float)
    h[:ms] = (seconds % 1 * 1000).to_i
    seconds = seconds.to_i
  end
  if options[:drop_seconds]
    h.delete(:ms)
    seconds = (seconds - seconds % 60)
  end
  durations = options[:months] ? DURATIONS2M : DURATIONS2
  durations.each do |key, duration|
    count = seconds / duration
    seconds = seconds % duration
    h[key.to_sym] = count if count > 0
  end
  h
end