class Faker::Time
def backward(days: 365, period: :all, format: nil)
-
(Time)
-
Parameters:
-
format
(Symbol
) -- The name of a DateTime format to use. -
period
(Symbol
) -- The time of day, if any. See {TIME_RANGES}. -
days
(Integer
) -- The maximum number of days to go into the past.
def backward(days: 365, period: :all, format: nil) time_with_format(date_with_random_time(Faker::Date.backward(days: days), period), format) end
def between(from:, to:, format: nil)
-
(Time)
-
Parameters:
-
format
(Symbol
) -- The name of a DateTime format to use. -
to
(Time, Date, DateTime
) -- The end of the usable time range. -
from
(Time, Date, DateTime
) -- The start of the usable time range.
def between(from:, to:, format: nil) from = get_time_object(from) to = get_time_object(to) time = Faker::Base.rand_in_range(from, to) time_with_format(time, format) end
def between_dates(from:, to:, period: :all, format: nil)
-
(Time)
-
Parameters:
-
format
(Symbol
) -- The name of a DateTime format to use. -
period
(Symbol
) -- The time of day, if any. See {TIME_RANGES}. -
to
(Date
) -- The end of the usable time range. -
from
(Date
) -- The start of the usable time range.
def between_dates(from:, to:, period: :all, format: nil) date = Faker::Date.between(from: from, to: to) time = date_with_random_time(date, period) time_with_format(time, format) end
def date_with_random_time(date, period)
def date_with_random_time(date, period) ::Time.local(date.year, date.month, date.day, hours(period), minutes, seconds) end
def forward(days: 365, period: :all, format: nil)
-
(Time)
-
Parameters:
-
format
(Symbol
) -- The name of a DateTime format to use. -
period
(Symbol
) -- The time of day, if any. See {TIME_RANGES}. -
days
(Integer
) -- The maximum number of days to go into the future.
def forward(days: 365, period: :all, format: nil) time_with_format(date_with_random_time(Faker::Date.forward(days: days), period), format) end
def get_time_object(time)
def get_time_object(time) time = ::Time.parse(time) if time.is_a? String time = time.to_time if time.respond_to?(:to_time) time end
def hours(period)
def hours(period) raise ArgumentError, 'invalid period' unless TIME_RANGES.key? period sample(TIME_RANGES[period].to_a) end
def minutes
def minutes seconds end
def seconds
def seconds sample((0..59).to_a) end
def time_with_format(time, format)
def time_with_format(time, format) format.nil? ? time : I18n.localize(time, format: format) end