Class: Range

Inherits:
Object
  • Object
show all
Defined in:
lib/can_has_support/range_time_ext.rb

Instance Method Summary collapse

Instance Method Details

#to_daysObject

Takes a range and converts it to an array of days

(Time.now..7.days.from_now).to_days



7
8
9
10
11
12
13
14
15
16
# File 'lib/can_has_support/range_time_ext.rb', line 7

def to_days
  return if first > last
  arr = []
  time = first
  while time <= last
    arr << time
    time += 1.day
  end
  return arr
end

#to_hoursObject

Takes a range and converts it to an array of hours

(Time.now..1.day.from_now).to_hours



22
23
24
25
26
27
28
29
30
31
# File 'lib/can_has_support/range_time_ext.rb', line 22

def to_hours
  return if first > last
  arr = []
  time = first
  while time <= last
    arr << time
    time += 1.hour
  end
  return arr
end