Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/faker/medical/extensions/time.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



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/faker/medical/extensions/time.rb', line 3

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
  date = Time.local(year, month, day)

  series = [date]
  if params[:series]
    params[:series].each do |some_time_after|
      series << series.last + (rand * some_time_after).ceil
    end
    return series
  end

  date
end