Skip to content

Instantly share code, notes, and snippets.

@mischa
Created December 23, 2008 09:49
Show Gist options
  • Save mischa/39296 to your computer and use it in GitHub Desktop.
Save mischa/39296 to your computer and use it in GitHub Desktop.
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