I’m trying to step every N days between two dates. I tried the following code but is wasn’t working because startDate and endDate are ActiveSupport::TimeWithZone objects and not DateTime objects like I thought.
startDate.step(endDate, step=7) { |d| puts d.to_s}
min.step(max, step=stepInt){ |d|
puts d.to_s
}
How do I covert the TimeWithZone object to a DateTime?
DateTimeis an old class which you generally want to avoid using.TimeandDateare the two you want to be using.ActiveSupport::TimeWithZoneacts likeTime.For stepping over dates you probably want to deal with
Dateobjects. You can convert aTime(orActiveSupport::TimeWithZone) into aDatewithTime#to_date: