class Faker::Time

Constants

TIME_RANGES

Public Class Methods

backward(days = 365, period = :all) click to toggle source
Calls superclass method Faker::Date.backward
# File lib/faker/time.rb, line 31
def backward(days = 365, period = :all)
  super(days).to_time + random_time(period)
end
between(from, to, period = :all) click to toggle source
Calls superclass method Faker::Date.between
# File lib/faker/time.rb, line 14
def between(from, to, period = :all)
  time_parameters = from.is_a?(::Time) && to.is_a?(::Time)

  if time_parameters
    random_time = Faker::Base::rand_in_range(from.to_f, to.to_f)
    random_time = ::Time.at(random_time)
  else
    random_time = super(from, to).to_time + random_time(period)
  end

  random_time
end
forward(days = 365, period = :all) click to toggle source
Calls superclass method Faker::Date.forward
# File lib/faker/time.rb, line 27
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/faker/time.rb, line 41
def hours(period)
  raise ArgumentError, 'invalid period' unless TIME_RANGES.has_key? period
  hour_at_period = TIME_RANGES[period].to_a.sample

  (60 * 60 * hour_at_period)
end
minutes() click to toggle source
# File lib/faker/time.rb, line 48
def minutes
  60 * seconds
end
random_time(period) click to toggle source
# File lib/faker/time.rb, line 37
def random_time(period)
  hours(period) + minutes + seconds
end
seconds() click to toggle source
# File lib/faker/time.rb, line 52
def seconds
  (0..59).to_a.sample
end