Module: FFaker::Date

Extended by:
Date, ModuleUtils
Included in:
Date
Defined in:
lib/ffaker/date.rb

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, luhn_check, underscore, unique

Methods included from RandomUtils

#fetch_sample, #rand, #shuffle

Instance Method Details

#backward(days = 365) ⇒ Object

Generates a random date up to ‘days` days in the past



16
17
18
19
20
21
# File 'lib/ffaker/date.rb', line 16

def backward(days = 365)
  from = ::Date.today - days
  to   = ::Date.today - 1

  between(from, to)
end

#between(from, to) ⇒ Object

Generates a random date between 2 dates



11
12
13
# File 'lib/ffaker/date.rb', line 11

def between(from, to)
  FFaker::Time.between(from, to).to_date
end

#birthday(min_age: 18, max_age: 65) ⇒ Object

Random birthday date (maximum age between 18 and 65) Keyword arguments: min_age, max_age



33
34
35
36
37
38
# File 'lib/ffaker/date.rb', line 33

def birthday(min_age: 18, max_age: 65)
  from = ::Date.today.prev_year(max_age + 1).next_day
  to = ::Date.today.prev_year(min_age)

  between(from, to)
end

#forward(days = 365) ⇒ Object

Generates a random date up to ‘days` days in the future



24
25
26
27
28
29
# File 'lib/ffaker/date.rb', line 24

def forward(days = 365)
  from = ::Date.today + 1
  to   = ::Date.today + days

  between(from, to)
end