Class: Faker::Time
Constant Summary collapse
- TIME_RANGES =
{ all: (0..23), day: (9..17), night: (18..23), morning: (6..11), afternoon: (12..17), evening: (17..21), midnight: (0..4) }.freeze
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.backward(days: 365, period: :all, format: nil) ⇒ Time
Produce a random time in the past (up to N days).
-
.between(from:, to:, format: nil) ⇒ Time
Produce a random time between two times.
-
.between_dates(from:, to:, period: :all, format: nil) ⇒ Time
Produce a random time between two dates.
-
.forward(days: 365, period: :all, format: nil) ⇒ Time
Produce a random time in the future (up to N days).
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale
Class Method Details
.backward(days: 365, period: :all, format: nil) ⇒ Time
Produce a random time in the past (up to N days).
114 115 116 |
# File 'lib/faker/default/time.rb', line 114 def backward(days: 365, period: :all, format: nil) time_with_format(date_with_random_time(Faker::Date.backward(days: days), period), format) end |
.between(from:, to:, format: nil) ⇒ Time
Produce a random time between two times.
38 39 40 41 42 43 44 |
# File 'lib/faker/default/time.rb', line 38 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 |
.between_dates(from:, to:, period: :all, format: nil) ⇒ Time
Produce a random time between two dates.
74 75 76 77 78 |
# File 'lib/faker/default/time.rb', line 74 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 |
.forward(days: 365, period: :all, format: nil) ⇒ Time
Produce a random time in the future (up to N days).
95 96 97 |
# File 'lib/faker/default/time.rb', line 95 def forward(days: 365, period: :all, format: nil) time_with_format(date_with_random_time(Faker::Date.forward(days: days), period), format) end |