class FactoryHelper::Time

Constants

TIME_RANGES

Public Class Methods

backward(days = 365, period = :all) click to toggle source
Calls superclass method FactoryHelper::Date::backward
# File lib/factory-helper/time.rb, line 24
def backward(days = 365, period = :all)
  super(days).to_time + random_time(period)
end
between(from=::Time.at(0), to=::Time.now, period = :all) click to toggle source
Calls superclass method FactoryHelper::Date::between
# File lib/factory-helper/time.rb, line 16
def between(from=::Time.at(0), to=::Time.now, period = :all)
  super(from, to).to_time + random_time(period)
end
forward(days = 365, period = :all) click to toggle source
Calls superclass method FactoryHelper::Date::forward
# File lib/factory-helper/time.rb, line 20
def forward(days = 365, period = :all)
  super(days).to_time + random_time(period)
end

Private Class Methods

hours(period) click to toggle source
# File lib/factory-helper/time.rb, line 34
def hours(period)
  raise ArgumentError, 'invalid period' unless TIME_RANGES.has_key? period
  hour_at_period = TIME_RANGES[period].to_a.sample(:random => FactoryHelper::Config.random)

  (60 * 60 * hour_at_period)
end
minutes() click to toggle source
# File lib/factory-helper/time.rb, line 41
def minutes
  60 * seconds
end
random_time(period) click to toggle source
# File lib/factory-helper/time.rb, line 30
def random_time(period)
  hours(period) + minutes + seconds
end
seconds() click to toggle source
# File lib/factory-helper/time.rb, line 45
def seconds
  (0..59).to_a.sample(:random => FactoryHelper::Config.random)
end