Class: FactoryHelper::Date

Inherits:
Base
  • Object
show all
Defined in:
lib/factory-helper/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, flexible, letterify, method_missing, numerify, parse, rand_in_range, regexify, translate

Class Method Details

.backward(days = 365) ⇒ Object



21
22
23
24
25
26
# File 'lib/factory-helper/date.rb', line 21

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

  between(from, to).to_date
end

.between(from = ::Date.today-10, to = ::Date.today+10) ⇒ Object



7
8
9
10
11
12
# File 'lib/factory-helper/date.rb', line 7

def between(from=::Date.today-10, to=::Date.today+10)
  from = get_date_object(from)
  to   = get_date_object(to)

  FactoryHelper::Base::rand_in_range(from, to)
end

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



28
29
30
31
32
33
34
# File 'lib/factory-helper/date.rb', line 28

def birthday(min_age = 18, max_age = 65)
  today= ::Date.today
  from = ::Date.new(today.year - min_age, today.month, today.day) - 1
  to   = ::Date.new(today.year - max_age, today.month, today.day) + 1

  between(from, to).to_date
end

.forward(days = 365) ⇒ Object



14
15
16
17
18
19
# File 'lib/factory-helper/date.rb', line 14

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

  between(from, to).to_date
end