Skip to content

Instantly share code, notes, and snippets.

@whitehat101
Last active April 10, 2017 01:39
Show Gist options
  • Save whitehat101/08f1d225676460c15269a561c4ebb087 to your computer and use it in GitHub Desktop.
Save whitehat101/08f1d225676460c15269a561c4ebb087 to your computer and use it in GitHub Desktop.
Normalize a flow of timestamps into ones suitable for charting
# 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