Class: Faker::Date

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/date.rb

Direct Known Subclasses

Time

Constant Summary

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, sample, shuffle, translate, unique, with_locale

Class Method Details

.backward(days = 365) ⇒ Object



26
27
28
29
30
31
# File 'lib/faker/date.rb', line 26

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

  between(from, to).to_date
end

.between(from, to) ⇒ Object



4
5
6
7
8
9
# File 'lib/faker/date.rb', line 4

def between(from, to)
  from = get_date_object(from)
  to   = get_date_object(to)

  Faker::Base.rand_in_range(from, to)
end

.between_except(from, to, excepted) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/faker/date.rb', line 11

def between_except(from, to, excepted)
  begin
    date = between(from, to)
  end while date == excepted

  date
end

.birthday(min_age = 18, max_age = 65) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/faker/date.rb', line 33

def birthday(min_age = 18, max_age = 65)
  t = ::Date.today
  top_bound, bottom_bound = prepare_bounds(t, min_age, max_age)
  years = handled_leap_years(top_bound, bottom_bound)

  from =  ::Date.new(years[0], t.month, t.day)
  to   =  ::Date.new(years[1], t.month, t.day)

  between(from, to).to_date
end

.forward(days = 365) ⇒ Object



19
20
21
22
23
24
# File 'lib/faker/date.rb', line 19

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

  between(from, to).to_date
end