Class: Time

Inherits:
Object show all
Defined in:
lib/mack-facets/extensions/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.random(start_time, end_time = Time.now) ⇒ Object

Generates a random Time between the start time and the end time.



26
27
28
# File 'lib/mack-facets/extensions/time.rb', line 26

def self.random(start_time, end_time = Time.now)
  start_time + (rand(end_time - start_time).to_i)
end

Instance Method Details

#to_dateObject



7
8
9
10
11
# File 'lib/mack-facets/extensions/time.rb', line 7

def to_date
  require 'date' # just in case
  jd = Date.__send__(:civil_to_jd, year, mon, mday, Date::ITALY)
  Date.new!(Date.__send__(:jd_to_ajd, jd, 0, 0), 0, Date::ITALY)
end

#to_datetimeObject

Raises:

  • (NoMethodError)


19
20
21
# File 'lib/mack-facets/extensions/time.rb', line 19

def to_datetime
  raise NoMethodError.new("to_datetime")
end