Ahhh… its one of the moments in life that make you so happy your a ruby developer.
class Time def round(seconds = 60) Time.at((self.to_f / seconds).round * seconds) end def floor(seconds = 60) Time.at((self.to_f / seconds).floor * seconds) end def round_to_closest_hour if self.min > 30 self.round(1.hour) else self.floor(1.hour) end end end
Source:
http://stackoverflow.com/questions/449271/how-to-round-a-time-down-to-the-nearest-15-minutes-in-ruby