Skip to content

Instantly share code, notes, and snippets.

@technicalpickles
Forked from jeffrafter/gist:35820
Created December 14, 2008 22:45
Show Gist options
  • Save technicalpickles/35824 to your computer and use it in GitHub Desktop.
Save technicalpickles/35824 to your computer and use it in GitHub Desktop.
intervals = []
time = @start_time
while (time < @end_time)
intervals << [time, time.next_interval]
time = time.next_interval
end
## Time ext
class Time
# Dividing time into intervals allows you to quickly set up periods. Calling
# interval on a time will return the start time of the current interval
# which is assumed to start on the hour. The value for step should be a
# factor of 60.
def interval(step = 6)
Time.mktime(year, month, day, hour, min - (min % step), 0)
end
# Grabs the start time of the next interval (see +interval+ for more details)
def next_interval(step = 6)
(self + step.minutes).interval(step)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment