Created
February 20, 2014 16:19
-
-
Save armstrongnate/9117450 to your computer and use it in GitHub Desktop.
Get hours, minutes, and seconds from time difference in ruby.
This file contains 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
# t1 and t2 are Time objects | |
# t is a class with attributes hours, minutes, and seconds | |
diff = t2 - t1 | |
%w(hours minutes seconds).each do |duration| | |
diff -= (t.send("#{duration}=", (diff / 1.send(duration)).round)).send(duration) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment