class TimeToday

Public Class Methods

any(d=Date.today) click to toggle source
# File lib/timetoday.rb, line 18
def self.any(d=Date.today)
  #seconds_in_day = (DateTime.now + 1).to_time - DateTime.now.to_time
  seconds_in_day = 86399.999461942 # result from above

  any_time = Time.at rand(seconds_in_day)
  day, mon, year = d.day, d.month, d.year
  s, min, hr = any_time.to_a.values_at 0,1,2
  Time.new(year, mon, day, hr, min, s)  
end
between(s1,s2) click to toggle source
# File lib/timetoday.rb, line 28
def self.between(s1,s2)
  rand Time.parse(s1)..Time.parse(s2)
end
future() click to toggle source
# File lib/timetoday.rb, line 32
def self.future()
  t = Time.now
  time_remaining = ((Time.now.to_date + 1).to_time - 1) - t
  t + rand(time_remaining)
end
new() click to toggle source
Calls superclass method
# File lib/timetoday.rb, line 13
def initialize()
  super()
  expressions()
end
within(duration) click to toggle source
# File lib/timetoday.rb, line 38
def self.within(duration)
  Time.now + rand(ChronicDuration.parse(duration))
end

Public Instance Methods

between(s) click to toggle source
# File lib/timetoday.rb, line 42
def between(s)
  expression = find_expression(s)
end

Private Instance Methods

expressions() click to toggle source
# File lib/timetoday.rb, line 48
def expressions()
  
  # e.g. 2-3 days
  get /(\d+)\s*-\s*(\d+)\s+days/ do |n1, n2|
    d = Date.today
    tt = TimeToday
    rand(tt.any(d+n1.to_i)..tt.any(d+n2.to_i)).to_time
  end
end