Class: Time

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

Overview

Time extensions

Class Method Summary collapse

Class Method Details

.rand(range = nil) ⇒ Time

This calls ‘DateTime.rand`.

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

Examples:


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

with a range


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

Parameters:

  • A (Range<Time..Time>)

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

Returns:

  • (Time)

    a random time



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

def self.rand(range = nil)
  DateTime.rand(range).to_time
end