class TimeUtil

Attributes

intervals[R]

Public Class Methods

new() click to toggle source
# File lib/svnx/util/timeutil.rb, line 9
def initialize 
  @intervals = Hash.new.tap do |h|
    h[:seconds] = 60
    h[:minutes] = 60
    h[:hours] = 24
    h[:days] = 7
  end
end

Public Instance Methods

to_units(seconds) click to toggle source

returns the value in seconds, minutes, hours, days, etc.

# File lib/svnx/util/timeutil.rb, line 19
def to_units seconds
  secs = seconds.to_i

  max = Hash.new.tap do |h|
    h[:seconds] = 120
    h[:minutes] = 120
    h[:hours] = 72
    h[:days] = 18
    h[:weeks] = 4
  end

  num = secs
  max.each do |field, value|
    if num < value
      return [ num, field ]
    elsif ival = @intervals[field]
      num /= ival
    end
  end
  nil
end