1

I'm with Rails 4:

I need to make a loop in a table to display time of the day as title of column, like that

8:00 | 8:30 | 9:00 .... 20:00 | 20:30 | 21:00

Do you have any idea how to define the loop? I've try complicated things with step() but meaby I have miss a easy way using Time?

Thanks

Yoann Augen
  • 1,966
  • 3
  • 21
  • 39

1 Answers1

1

You could use Rails DateTime like this (for n steps you want)

startdate = DateTime.new(2001,2,3) 
interval = 30
formatstr = '%H:%M'
(0..n).map{|offset| startdate + (offset * interval).minutes }
      .map{|date| date.strftime(formatstr)}
Daniel Schmidt
  • 11,605
  • 5
  • 38
  • 70