Skip to content

Instantly share code, notes, and snippets.

@armstrongnate
Created February 20, 2014 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save armstrongnate/9117450 to your computer and use it in GitHub Desktop.
Save armstrongnate/9117450 to your computer and use it in GitHub Desktop.
Get hours, minutes, and seconds from time difference in ruby.
# 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