Created
December 23, 2008 09:49
-
-
Save mischa/39296 to your computer and use it in GitHub Desktop.
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
class MischaTime < Struct.new(:hours, :minutes, :seconds); end | |
def time_diff(t1, t2) | |
if seconds(t1) > seconds(t2) | |
(one_day - t1.seconds) + seconds(t2) | |
else | |
seconds(t2) - seconds(t1) | |
end | |
end | |
def seconds(time) | |
(time.hours * 3600) + (time.minutes * 60) + time.seconds | |
end | |
def one_day | |
24 * 3600 | |
end | |
puts time_diff(MischaTime.new(1, 2, 3), MischaTime.new(4, 5, 6)).to_s | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment