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(legacy_days = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, days: 365, period: :all, format: nil) ⇒ Time
Produce a random time in the past (up to N days).
-
.between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_format = NOT_GIVEN, from:, to:, format: nil) ⇒ Time
Produce a random time between two times.
-
.between_dates(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, from:, to:, period: :all, format: nil) ⇒ Time
Produce a random time between two dates.
-
.forward(legacy_days = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, 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, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale
Class Method Details
.backward(legacy_days = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, days: 365, period: :all, format: nil) ⇒ Time
Produce a random time in the past (up to N days).
137 138 139 140 141 142 143 144 145 |
# File 'lib/faker/default/time.rb', line 137 def backward(legacy_days = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, days: 365, period: :all, format: nil) warn_for_deprecated_arguments do |keywords| keywords << :days if legacy_days != NOT_GIVEN keywords << :period if legacy_period != NOT_GIVEN keywords << :format if legacy_format != NOT_GIVEN end time_with_format(date_with_random_time(Faker::Date.backward(days: days), period), format) end |
.between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_format = NOT_GIVEN, from:, to:, format: nil) ⇒ Time
Produce a random time between two times.
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/faker/default/time.rb', line 41 def between(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_format = NOT_GIVEN, from:, to:, format: nil) warn_for_deprecated_arguments do |keywords| keywords << :from if legacy_from != NOT_GIVEN keywords << :to if legacy_to != NOT_GIVEN keywords << :format if legacy_format != NOT_GIVEN end 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(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, from:, to:, period: :all, format: nil) ⇒ Time
Produce a random time between two dates.
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/faker/default/time.rb', line 84 def between_dates(legacy_from = NOT_GIVEN, legacy_to = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, from:, to:, period: :all, format: nil) warn_for_deprecated_arguments do |keywords| keywords << :from if legacy_from != NOT_GIVEN keywords << :to if legacy_to != NOT_GIVEN keywords << :period if legacy_period != NOT_GIVEN keywords << :format if legacy_format != NOT_GIVEN end date = Faker::Date.between(from: from, to: to) time = date_with_random_time(date, period) time_with_format(time, format) end |
.forward(legacy_days = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, days: 365, period: :all, format: nil) ⇒ Time
Produce a random time in the future (up to N days).
112 113 114 115 116 117 118 119 120 |
# File 'lib/faker/default/time.rb', line 112 def forward(legacy_days = NOT_GIVEN, legacy_period = NOT_GIVEN, legacy_format = NOT_GIVEN, days: 365, period: :all, format: nil) warn_for_deprecated_arguments do |keywords| keywords << :days if legacy_days != NOT_GIVEN keywords << :period if legacy_period != NOT_GIVEN keywords << :format if legacy_format != NOT_GIVEN end time_with_format(date_with_random_time(Faker::Date.forward(days: days), period), format) end |