Skip to content

Instantly share code, notes, and snippets.

@byelipk
Created June 3, 2017 13:57
Show Gist options
  • Save byelipk/8f776409f0e293c41181223038323630 to your computer and use it in GitHub Desktop.
Save byelipk/8f776409f0e293c41181223038323630 to your computer and use it in GitHub Desktop.
Simple timer app in Ruby
def time_diff(start_time, end_time)
seconds_diff = (start_time - end_time).to_i.abs
hours = seconds_diff / 3600
seconds_diff -= hours * 3600
minutes = seconds_diff / 60
seconds_diff -= minutes * 60
seconds = seconds_diff
"#{hours.to_s.rjust(2, '0')}:#{minutes.to_s.rjust(2, '0')}:#{seconds.to_s.rjust(2, '0')}"
end
start = Time.now
loop do
sleep(1)
STDOUT.write("\rTime Elpased: " << time_diff(start, Time.now))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment