-
-
Save technicalpickles/35824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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