class Sensor::TimeRange

Attributes

end[R]
start[R]

Public Class Methods

new(start_date, end_date) click to toggle source
# File lib/sensor/time_range.rb, line 6
def initialize(start_date, end_date)
  @start = timify(start_date)
  @end = timify(end_date, true)
end

Public Instance Methods

end_date() click to toggle source
# File lib/sensor/time_range.rb, line 15
def end_date
  datify(@end)
end
start_date() click to toggle source
# File lib/sensor/time_range.rb, line 11
def start_date
  datify(@start)
end

Protected Instance Methods

datify(time) click to toggle source
# File lib/sensor/time_range.rb, line 20
def datify(time)
  Date.new(time.year, time.month, time.day)
end
timify(date, as_end = false) click to toggle source
# File lib/sensor/time_range.rb, line 24
def timify(date, as_end = false)
  if date.kind_of?(String)
    Chronic.parse(date)
  elsif date.kind_of?(Date)
    as_end ? (date + 1).to_time - 1 : date.to_time
  elsif date.kind_of?(Time)
    date
  else
    raise "Unknown date parameter: #{date}"
  end
end