Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/faker_patient.rb

Overview

mixin random time function from jroller.com/obie/entry/random_times_for_rails

Class Method Summary collapse

Class Method Details

.random(params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/faker_patient.rb', line 4

def self.random(params={})
  years_back = params[:year_range] || 5
  year = (rand * (years_back)).ceil + (Time.now.year - years_back)
  month = (rand * 12).ceil
  day = (rand * 31).ceil
  series = [date = Time.local(year, month, day)]
  if params[:series]
    params[:series].each do |some_time_after|
      series << series.last + (rand * some_time_after).ceil
    end
    return series
  end
  date
end