Class: DateTime

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

Overview

DateTime extensions

Class Method Summary collapse

Class Method Details

.rand(range = nil) ⇒ DateTime

This is called by ‘Date.rand` and `Time.rand`.

The default range is +/- 10000 days from now, which is the same as ‘Date.rand` and `Time.rand`.

Examples:


DateTime.rand
=> "2014-12-31 12:59:59Z" 

with a range


now = DateTime.now
range = (now - 10000)..(now + 10000)
DateTime.rand(range)

Parameters:

  • A (Range<DateTime..DateTime>)

    range of potential date-times, or nil for the default range.

Returns:



29
30
31
# File 'lib/sixarm_ruby_date_time_rand/date_time.rb', line 29

def self.rand(range = nil)
  range ? Kernel.rand(range) : (DateTime.now + Kernel.rand(-10000..10000))
end