Class: Date

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

Overview

Date extensions

Class Method Summary collapse

Class Method Details

.rand(range = nil) ⇒ Date

This calls ‘DateTime#rand`.

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

Examples:


Date.rand
=> "2014-12-31" 

with a range


today = Date.today
range = (today - 10000)..(today + 10000)
Date.rand(range)

Parameters:

  • A (Range<Date..Dateb>)

    range of potential dates, or nil for the default.

Returns:

  • (Date)

    a random daate



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

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