class Faker::Time
Constants
- TIME_RANGES
Public Class Methods
backward(days = 365, period = :all, format = nil)
click to toggle source
Calls superclass method
Faker::Date::backward
# File lib/faker/time.rb, line 23 def backward(days = 365, period = :all, format = nil) time_with_format(date_with_random_time(super(days), period), format) end
between(from, to, period = :all, format = nil)
click to toggle source
Calls superclass method
Faker::Date::between
# File lib/faker/time.rb, line 14 def between(from, to, period = :all, format = nil) time = period == :between ? rand(from..to) : date_with_random_time(super(from, to), period) time_with_format(time, format) end
forward(days = 365, period = :all, format = nil)
click to toggle source
Calls superclass method
Faker::Date::forward
# File lib/faker/time.rb, line 19 def forward(days = 365, period = :all, format = nil) time_with_format(date_with_random_time(super(days), period), format) end
Private Class Methods
date_with_random_time(date, period)
click to toggle source
# File lib/faker/time.rb, line 29 def date_with_random_time(date, period) ::Time.local(date.year, date.month, date.day, hours(period), minutes, seconds) end
hours(period)
click to toggle source
# File lib/faker/time.rb, line 37 def hours(period) raise ArgumentError, 'invalid period' unless TIME_RANGES.has_key? period sample(TIME_RANGES[period].to_a) end
minutes()
click to toggle source
# File lib/faker/time.rb, line 42 def minutes seconds end
seconds()
click to toggle source
# File lib/faker/time.rb, line 46 def seconds sample((0..59).to_a) end
time_with_format(time, format)
click to toggle source
# File lib/faker/time.rb, line 33 def time_with_format(time, format) format.nil? ? time : I18n.l( DateTime.parse(time.to_s), :format => format ) end