Created
January 12, 2018 13:53
-
-
Save matugm/9683a5dd81bb955b3be3dbfb6f20ef18 to your computer and use it in GitHub Desktop.
Revisions
-
matugm created this gist
Jan 12, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ require 'time' require 'pp' objects = [Time.strptime("20", "%M"), Time.strptime("21", "%M"), Time.strptime("25", "%M"),Time.strptime("26", "%M")] @range = Hash.new { |hash, key| hash[key] = [] } def add_into_time_range(time) base = time.min - (time.min % 5) key = "#{time.hour}:#{base}" @range[key] << time end objects.each { |t| add_into_time_range(t) } pp @range # { # "14:20"=>[2018-01-12 14:20:00 +0100, 2018-01-12 14:21:00 +0100], # "14:25"=>[2018-01-12 14:25:00 +0100, 2018-01-12 14:26:00 +0100] # }