Created
June 3, 2017 13:57
-
-
Save byelipk/8f776409f0e293c41181223038323630 to your computer and use it in GitHub Desktop.
Simple timer app in Ruby
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
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