module FFaker::Date

Public Instance Methods

backward(days = 365) click to toggle source

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

# 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) click to toggle source

Generates a random date between 2 dates

# 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) click to toggle source

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

# 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) click to toggle source

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

# File lib/ffaker/date.rb, line 24
def forward(days = 365)
  from = ::Date.today + 1
  to   = ::Date.today + days

  between(from, to)
end