Class: Time
- Inherits:
-
Object
- Object
- Time
- Defined in:
- lib/kuali-sakai-common-lib/core-ext.rb
Class Method Summary collapse
-
.random(params = {}) ⇒ Object
Using the :year_range option (or no option), this method creates a Time object of a random value, within the year range specified (default is 5 years in the past).
Class Method Details
.random(params = {}) ⇒ Object
Using the :year_range option (or no option), this method creates a Time object of a random value, within the year range specified (default is 5 years in the past).
Using the :series option, this method returns an array containing a randomized Time object as its first element (limited by the specified :year_range value). Subsequent elements will be Time objects with values putting them later than the prior element, within the specified range value (see examples).
Usage Examples:
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/kuali-sakai-common-lib/core-ext.rb', line 39 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 |