Last active
April 10, 2017 01:39
-
-
Save whitehat101/08f1d225676460c15269a561c4ebb087 to your computer and use it in GitHub Desktop.
Normalize a flow of timestamps into ones suitable for charting
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 characters
# HH:17:30 ... HH:27:30 => HH:20:00 | |
def norm_time t | |
i = t.to_i | |
i /= 300.0 | |
i = i.round # round to nearest 5 minutes | |
i /= 2 # floor to nearest 10 minutes | |
Time.at i*600 | |
end | |
s = Time.now | |
1000.times do | |
puts "#{s} => #{norm_time s}" | |
s += 15 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment