-
-
Save thetrav/377d47bea40761c7f5f511048b54cc71 to your computer and use it in GitHub Desktop.
days
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
class Days | |
def initialize(first_timestamp, last_timestamp) | |
@first_timestamp = first_timestamp | |
@last_timestamp = last_timestamp | |
end | |
def each | |
return enum_for(:each) unless block_given? | |
current_timestamp = @first_timestamp - 30 * 60 | |
while current_timestamp < @last_timestamp | |
yield current_timestamp | |
current_timestamp += 24 * 60 * 60 | |
end | |
end | |
def chunked | |
return enum_for(:chunked) unless block_given? | |
each.chunk(&:year).each do |year, timestamps| | |
yield year, timestamps.chunk(&:month) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment