I'm looking for an efficient way, in Ruby 1.9.x/Rails 3.2.x, to iterate between two DateTime objects, with a one-hour step.
('2013-01-01'.to_datetime .. '2013-02-01'.to_datetime).step(1.hour) do |date|
...
end
I understand that an issue with this is that 1.hour
is just the number of seconds, but my attempts to convert that to a DateTime object and use that as the step doesn't work either.
I looked at "Beware of Ruby Sugar". It mentions, near the bottom, that DateTime has a direct step
method. I confirmed this by running methods
on a DateTime object, but I cannot find any documentation on step
in DateTime, in either Ruby's or Rails' documents.
question from:
https://stackoverflow.com/questions/14555205/iterating-between-two-datetimes-with-a-one-hour-step 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…