Module: FFaker::Time
Constant Summary
collapse
- MONTHS =
%w(January February March April May June July August September October November December).freeze
Instance Method Summary
collapse
const_missing, k, underscore
#fetch_sample, #rand, #shuffle
Instance Method Details
#between(from, to) ⇒ Object
38
39
40
|
# File 'lib/ffaker/time.rb', line 38
def between(from, to)
::Time.at(from + rand * (to.to_f - from.to_f))
end
|
#date(params = {}) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/ffaker/time.rb', line 14
def date(params = {})
years_back = params[:year_range] || 5
latest_year = params [:year_latest] || 0
year = (rand * years_back).ceil + (::Time.now.year - latest_year - years_back)
month = (rand * 12).ceil
day = (rand * 31).ceil
hours = params[:hours] || 0
minutes = params[:minutes] || 0
series = [date = ::Time.local(year, month, day, hours, minutes)]
if params[:series]
params[:series].each do |some_time_after|
series << series.last + (rand * some_time_after).ceil
end
return series
end
date.strftime '%Y-%m-%d %T %z'
end
|
#datetime(params = {}) ⇒ Object
32
33
34
35
36
|
# File 'lib/ffaker/time.rb', line 32
def datetime(params = {})
hours = params[:hours] || (rand * 12).ceil
minutes = params[:minutes] || (rand * 59).ceil
date(params.merge(hours: hours, minutes: minutes))
end
|
#month ⇒ Object
10
11
12
|
# File 'lib/ffaker/time.rb', line 10
def month
fetch_sample(MONTHS)
end
|